How does `let` work in Scheme?

How does `let` work in Scheme?

While not exactly the problem youre experiencing, but an aside based on your questioning about the sequence of evaluating the arguments, let is also syntactic sugar for a lambda followed by its arguments that are first evaluated and then passed to the lambda which is then evaluated.

For instance:

(let ((a (list 1 2 3))
      (b (list 4 5 6)))
     (cons a b))

is the same as:

((lambda (list-a list-b) (cons list-a list-b)) (list 1 2 3) (list 4 5 6))

So, if youre ever wondering about evaluation sequence, the arguments are evaluated fully before the body is evaluated (and one argument cannot refer to an argument preceding it … use let* for something that requires bindings like that).

You need to put another set of parentheses around your let declarations:

(define (case-one-helper str)
  (let ((temp (substring str (+ 3 (string-contains str my)))))
    (substring temp (string-contains temp  ))))

How does `let` work in Scheme?

Leave a Reply

Your email address will not be published.