How to obtain my function definition in MIT Scheme?
Asked Answered
J

2

7

In JavaScript, I can retrieve the "source code" definition of a function, for example:

​function alert_Hi() {
    alert("Hi");
}

alert(alert_Hi);

will return exactly what I typed. http://jsfiddle.net/DuCqJ/

How can I do this in MIT Scheme?

I remember seeing something that returns #compound-procedure or something, but what I really want is the "source code".

Jansen answered 26/8, 2012 at 11:6 Comment(0)
L
9

You might try pp

(define (display-hi) (display "Hi"))
(pp display-hi) =>
(named-lambda (display-hi)
  (display "Hi"))

MIT-Scheme debugging aids

Leigh answered 6/1, 2013 at 17:26 Comment(0)
I
4

JavaScript is fully interpreted, so it has full function definitions lying around even after you've defined them. Scheme is not actually fully interpreted; it compiles functions (and a few other constructs, I think) down to a non-readable representation and throws away the initial code.

You could probably get it to store the initial textual representation of a function at runtime using some macro tricks, but I'm inclined to believe that this would be more trouble than it's worth.

If you don't mind me asking, why do you need the textual representation of a defined function at runtime?

Inlay answered 26/8, 2012 at 15:18 Comment(1)
Because I'm lazy and I want to say (display-function myFunction) instead of scrolling the editor back up :PJansen

© 2022 - 2024 — McMap. All rights reserved.