Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 308
agam Avatar asked Dec 13 '22 04:12

agam


1 Answers

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.

like image 59
John Clements Avatar answered Dec 28 '22 01:12

John Clements