How to obtain my function definition in MIT Scheme?

こ雲淡風輕ζ 提交于 2019-12-10 14:09:32

问题


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


回答1:


You might try pp

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

MIT-Scheme debugging aids




回答2:


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?



来源:https://stackoverflow.com/questions/12129581/how-to-obtain-my-function-definition-in-mit-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!