Why is this legal (rocket) scheme?
I was going through htdp and found this somewhere in the beginning: -
Explain why the following sentences are illegal definitions: 1. (define (f 'x) x)
However, it works fine in a racket:
> (define (f 'x) x)
> (f 'a)
3
> (define a 5)
> (f a)
3
Obviously I'm missing something ... what exactly?
+3
source to share
2 answers
Short answer: you shouldn't use the full "#lang racket" language. Languages ββof instruction eliminate the potentially confusing additional capabilities of the language you encounter.
In this case, your definition is interpreted as a function named f with an optional argument called quotation, which defaults to "x".
Set your language level to Beginner Learner and you will get a much smarter answer.
+12
source to share