My friend shows this to me, and I am really curious why it works like this. I at first thought that it's gonna be a syntax error, but it doesn't... Here're some of my experiments:
> (lambda lambda lambda)
#<procedure>
> ((lambda lambda lambda))
'()
> ((lambda lambda lambda) 1 2 3 4 5 6 7)
'(1 2 3 4 5 6 7)
> (lambda lambda foo)
#<procedure>
> ((lambda lambda foo))
foo: undefined;
cannot reference an identifier before its definition
> (lambda lambda 1 2 3 4 5)
#<procedure>
> ((lambda lambda 1 2 3 4 5))
5
> (lambda foo lambda)
. lambda: bad syntax in: lambda
> (lambda 1 2 3)
. lambda: bad argument sequence in: 1
> ((lambda) 1 2 3)
. lambda: bad syntax in: (lambda)
So it seems:
lambda
, lambda
could be arg-ids?lambda
, lambda
could be a list constructor?Ohhh I got it. lambda
could be shadowed!
> ((lambda (lambda) (+ 1 lambda)) 7)
8
Also, the syntax given at https://docs.racket-lang.org/guide/lambda.html is not entirely correct because at arg-ids
position, an identifier could be there! This will bind the list of arguments with the identifier:
> ((lambda foo foo) 1 2 3 4)
'(1 2 3 4)
These explain it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With