So as far as I understand, the following: let
, let*
, letrec
and letrec*
are synthetics sugars used in Scheme/Racket.
Now, if I have a simple program:
(let ((x 1)
(y 2))
(+ x y))
It is translated into:
((lambda (x y) (+ x y)) 1 2)
If I have:
(let* ((x 1)
(y 2))
(+ x y))
It is translated into:
((lambda (x) ((lambda (y) (+ x y))) 2) 1)
Now, for my first question, I understand the meaning of a letrec
expression, which enables one to use recursion inside a let, but I do not understand how exactly it is done. What is letrec
translated to?
For example, what will
(letrec ((x 1)
(y 2))
(+ x y))
be translated into?
The second question is similar about letrec*
- But for letrec*
I do not understand how exactly it differs from letrec
? And also, what will a letrec*
expression be translated into?
letrec
is not translated into anything.letrec
is a primitive form of the language. (And, for what it’s worth, in Racket,let
is also a primitive form in Racket, not a macro on top oflambda
, but that’s much more of a subjective design choice.) – Osteomalacialetrec
, the same way there is an equivalent expression forlet
andlet*
(such as I specified in my examples)? – Estradiolletrec
andletrec*
. (so, this might even be a duplicate...) – Raina