Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain my function definition in MIT Scheme?

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".

like image 346
Tina CG Hoehr Avatar asked Aug 26 '12 11:08

Tina CG Hoehr


2 Answers

You might try pp

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

MIT-Scheme debugging aids

like image 63
Nick Russell Avatar answered Sep 20 '22 09:09

Nick Russell


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?

like image 25
Inaimathi Avatar answered Sep 22 '22 09:09

Inaimathi