tags:

views:

53

answers:

3

The ipython python shell has a wonderful feature, whereby you can type:

foo??

and see the text of function foo.

Does scheme (in particular, MIT scheme), have anything like this?

I want to be able to say

(define (foo x) (* x x))

and later view (or even operate on) the list (* x x).

Is there a way to do this?

+1  A: 

Not by default in any Scheme I know. What you can do is define a macro that does what "define" does and in addition stores the body of the function in a hash table or an alist or whatever. That will only work on code that you control, of course.

Mark Probst
mm, i was thinking about doing something like that...great, thanks!
billc
A: 

There's no reliable, portable way to do this.

Oliver N.
A: 

The general structure of a Scheme function is (define (<name> <arg1> <arg2> ... ) <expr1> <expr2> ... <exprn>). Extending Mark Probst's suggestion, you could define a macro that defines a quoted version of the function, which you could then apply cddr to to get a list of the function's expressions.

Evan Meagher