mahbuhsj
mahbuhsj

Reputation: 33

Lisp Scheme : let to lambda

I am new to Lisp Scheme. I came across this code which uses "let".How do I replace it with lambda

Here is the code

    (define Gen-Decoder-A
      (lambda (p)
        (define check-decode
          (lambda (n) 
            (num-valid-words (encode-p p (encode-n n))))
          )
        (let ((decode-compare (map check-decode abc-nums)))
          (encode-n (get-position (apply max decode-compare) decode-compare)))
        ((lambda 
        )
      )

Here is the link to the full code : https://github.com/corypisano/CS314/blob/master/Project2/decode.ss

The let is in Gen-Decoder-A Help me change let to lambda

Upvotes: 0

Views: 420

Answers (1)

Óscar López
Óscar López

Reputation: 236122

A let is just syntactic sugar for a lambda - the letvariables can be rewritten as lambda parameters that get bound when calling the lambda. For example, this expression:

(let ((decode-compare (map check-decode abc-nums)))
  (encode-n (get-position (apply max decode-compare) decode-compare)))

Is equivalent to this:

((lambda (decode-compare)
  (encode-n (get-position (apply max decode-compare) decode-compare)))
 (map check-decode abc-nums))

Upvotes: 3

Related Questions