syntaxschemerackethtdp

Why is this legal (racket) 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 racket:

> (define (f 'x) x)
> (f 'a)
3
> (define a 5)
> (f a)
3

Obviously, I'm missing something ... what, exactly ?


Solution

  • Short answer: you should not be using the full "#lang racket" language. The teaching languages strip out the potentially confusing advanced features of the language that you're encountering.

    In this case, your definition is being interpreted as a function called f with an optional argument called quote whose default value is provided by 'x'.

    Set the language level to Beginning Student, and you'll get a much more reasonable answer.