im trying to convert from a let-form to an unamed procedure form and i just can't get the hang of it.
the let procedure is this.
(define max-recursive (lambda (lst)
(if (null? (cdr lst))
(car lst)
(let ((m0 (car lst))
(m1 (max-recursive (cdr lst))))
(if (> m0 m1)
m0
m1
)
)
)))
and what i've done so far is this
(define max-recursive (lambda (lst)
(if (null? (cdr lst))
(car lst)
((lambda (m0 m1)
(if (> m0 m1)
m0
m1
)
)
car lst (max-recursive (cdr lst)))
)))
any help would be appreciated thank you.
You almost got it! only a couple of parenthesis were missing around the expression
car lst
. Try this:The explanation is as follows. A
let
form like this one:... is just syntactic sugar for a
lambda
expression applied to some parameters. The previouslet
is equivalent to this:Notice that in both cases the value
10
ends up bound to a variable namedx
, and the body of thelet
expression is the same as the body of thelambda
expression