문제

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

도움이 되었습니까?

해결책

You might try pp

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

MIT-Scheme debugging aids

다른 팁

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top