Search code examples
lambdafunctional-programmingschemesicplet

How to express let* as a lambda expression (not the regular let)


I have a scheme related question, how can we implement let* as a lambda expression. To be more precise, I am not wondering about the "regular" let, but the let with * which lets us use one let expression within another.


Solution

  • The let* form is a series of nested lambdas. For example, this:

    (let* ((a 10)
           (b (+ 10 a)))
      (+ a b))
    

    Is equivalent to this:

    ((lambda (a)
       ((lambda (b)
          (+ a b))
        (+ 10 a)))
     10)