2
votes

I thought this was a pretty trivial problem but I haven't seen any good example of this yet. I need to define a lambda expression that takes no arguments and will always return 0.

How would I define a lambda expression that doesn't take any arguments and returns something?

3
FYI a function with no arguments is often called a thunk. - WorBlux

3 Answers

8
votes

What's wrong with (lambda () 0) ?

4
votes

Apart from the obvious answer of (lambda () 0), many Scheme implementations provide a const function that takes a value and returns a function that returns that value no matter what arguments (or lack thereof) are given.

4
votes
(define (always n)
  (lambda ignore n))

> (define always-0 (always 0))
> (always-0 10)
0
> (always-0 'a 'b' 'c)
0
> (always-0)
0