In scheme, why is this:
(define foo
(lambda (x)
42))
considered better style than this:
(define (foo x)
42)
And is there any reason to favour one over the other?
I don't think that's considered better style, the first is redundant. The real question is whether you define the named function foo
or just use lambda
instead. If you've already decided to make a named function foo
then I don't see why you would put the lambda
inside. lambda
relieves you of having to separately name and define every little function you make, so that's really where the decision is: is this function important enough to be defined and named separately.