In fact, the lambda
in your code is receiving parameters, and an aribtrary number of them. The syntax for a lambda
with no parameters is different:
(let ([f (lambda () 1)]) (f))
=> 1
The lambda
expression in the question is something else:
(lambda x x)
It receives a variable number of arguments as a list, and then returns them. You named it f
, and when it's invoked like this:
(f 1 2 3 4)
All of the arguments get bound to x
, a list and then the value of x
is returned:
'(1 2 3 4)
So, f
is nothing more than an identity function that receives multiple arguments. Perhaps this answer will clarify how variadic functions are defined in Scheme. For completeness' sake, here's an example of a lambda
that receives a single argument and returns it:
(let ([f (lambda (x) x)]) (f 1))
=> 1
So there you have it, that's how we define lambda
s that receive 0, 1 or many parameters.