I'm currently learning Scheme (using Racket), but one of the challenges I'm coming upon is trying to execute the following bit of code, which is meant to execute Racket code from user input using eval
:
(display (eval (read)))
Here's some of the weird behavior I've observed so far:
(display (eval (read)))
in the definition window prompts for keyboard input, as expected, when the definitions are run. However, providing the input
((lambda (x) (+ x 1)) 1)
gives the error
?: function application is not allowed; no #%app syntax transformer is bound in: ((lambda (x) (+ x 1)) 1)
On the other hand, using
(display ((eval (read)) 1))
and providing input
(lambda (x) (+ x 1))
returns the error
lambda: unbound identifier; also, no #%app syntax transformer is bound in: lambda
- However, running
(display (eval (read)))
and providing((lambda (x) (+ x 1)) 1)
in the console pane, as opposed to the definitions pane, prints out2
, as expected.
What is the reason for this behavior?
eval
because you're curious, or are you trying to do something that you don't know how to do otherwise? – Yondereval
because I'm curious, not because I'm trying to do any workarounds. – Houseclean