Actually, both versions of foldr
"with lambda
" and "without lambda
" are the same, the version "without" is just syntactic sugar for the version "with", they're completely equivalent (except for the fact that the parameter's order changed, but that's nothing).
Now, the myFunc1
procedure is a different thing. You're passing the last two parameters in the wrong order, but that's the least of your problems - what you wrote is not equivalent, a let
simply returns the value of the last expression and will be evaluated exactly once when foldr
is called, whereas a lambda
is an anonymous procedure that can receive parameters and will be executed multiple times inside foldr
. Even more, the syntax in let
is wrong and it won't compile. To put it another way: these two lines mean completely different things and the let
version (after fixing the syntax error) will never work as a function parameter for foldr
:
(lambda (acc x) (cons (proced acc) x))
(let ((acc x) x) (cons (proced acc)))
Perhaps you're confused because a let
form can be expressed in terms of lambda
, as demonstrated here. But the opposite is not true! you can not replace a lambda
with a let
... unless it happens to return a lambda
, but that's precisely what you're trying to avoid.