What would be the definition of lambda let in Scheme / Racket?

Today I'm trying to figure out how to work in the context of the lambda calculus in Scheme / Racket, but I can't figure out how to write the let equivalent as a lambda function.

I think its general form should be something like this:

((lambda (p1 p2...) body) v1 v2...)

      

but this is definitely not a complete definition of a function.

Any ideas of a correct / complete definition for this?

Thank you in advance!

+3


source to share


2 answers


Your example

((lambda (p1 p2 ...) body) v1 v2 ...)

      

is exactly what

(let ([p1 v1] [p2 v2] ...) body)

      



facilities.

You can turn your example into a macro like this:

#lang racket

(define-syntax my-let
  (syntax-rules ()
    [(_my-let ([p1 v1] [p2 v2] ...) body)
     ((lambda (p1 p2 ...) body) v1 v2 ...)]))

(my-let ([x 1]
         [y 2])
  (+ x y))

      

The result of the program is 3.

+5


source


From R5RS definition let

:



(define-syntax let
  (syntax-rules ()
    ((let ((name val) ...) body1 body2 ...)
      ((lambda (name ...) body1 body2 ...)
        val ...))
    ((let tag ((name val) ...) body1 body2 ...)
      ((letrec ((tag (lambda (name ...)
                       body1 body2 ...)))
        tag)
      val ...))))

      

+4


source







All Articles