### I need help converting between the let form and unnamed procedure form

1

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.

2012-04-04 20:18
by wyatt

4

You almost got it! only a couple of parenthesis were missing around the expression `car lst`. Try this:

``````(define max-recursive
(lambda (lst)
(if (null? (cdr lst))
(car lst)
((lambda (m0 m1)
(if (> m0 m1)
m0
m1))
(car lst) ;here was the error
(max-recursive (cdr lst))))))
``````

The explanation is as follows. A `let` form like this one:

``````(let ((x 10))
x)
``````

... is just syntactic sugar for a `lambda` expression applied to some parameters. The previous `let` is equivalent to this:

``````((lambda (x)
x)
10)
``````

Notice that in both cases the value `10` ends up bound to a variable named `x`, and the body of the `let` expression is the same as the body of the `lambda` expression

2012-04-04 20:41
by Óscar López
Thank you but i figured it out just a few minutes after posting - wyatt 2012-04-05 02:57