Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print definition of a symbol without evaluation in Scheme?

If I want to print function definition for a symbol, what should I do?

like image 274
eonil Avatar asked Jun 13 '11 09:06

eonil


People also ask

What does symbol mean in Scheme?

In Scheme and Racket, a symbol is like an immutable string that happens to be interned so that symbols can be compared with eq? (fast, essentially pointer comparison). Symbols and strings are separate data types. One use for symbols is lightweight enumerations.

How do you define a constant in a Scheme?

Just define the value at the toplevel like a regular variable and then don't change it. To help you remember, you can adopt a convention for naming these kinds of constants - I've seen books where toplevel variables are defined with *stars* around their name.

How do you check if a number is even in Scheme?

If a number is evenly divisible by 2 with no remainder, then it is even. You can calculate the remainder with the modulo operator % like this num % 2 == 0 . If a number divided by 2 leaves a remainder of 1, then the number is odd. You can check for this using num % 2 == 1 .


1 Answers

If I understand correctly, you want a function print-function such that after

(define (foo x) (cons x x))

it will behave as

> (print-function foo)
(lambda (x) (cons x x))

Standard Scheme doesn't have a facility for that. The reason is Scheme implementations may, and generally do, compile functions into a different representation (bytecode, machine code).

Some Schemes may keep the function definition around; check your implementation's manual.

like image 111
Fred Foo Avatar answered Oct 15 '22 21:10

Fred Foo