prog


let is just a macro for a function application

1 2020-02-11 03:03

Scheme beginner here. I've just read SICP which in the end doesn't teach much about Scheme itself.
I was baffled with the meta-circular evaluator so I'm beginning to read _Lisp in Small Pieces_ by Christian Queinnec.

I found this in a footnote in the first pages. I thought it was interesting and I'm sharing it here.

(let ((x π₁)) π₂) ≡ ((lambda (x) π₂) π₁)

As an example, an expression like (let ((a 3) (b 4)) (+ a b)) would expand to ((lambda (a b) (+ a b)) 3 4)

So, the macro for the basic let is simply

(define-syntax let
  (syntax-rules ()
    ((let ((var val) ...) body ...)
      ((lambda (var ...) body ...) val ...))))

Everything about this language is so simple and nice. Tell me Scheme is not dead and there's a future for it. I can't help reading about it but I have this awful feeling that I'm wasting my time because it's absolutely useless in the real world and that I should learn Javascript instead.

2 2020-02-11 03:15

Another example is the special form begin which is equivalent to this function application:

(begin α β) ≡ ((lambda (void) β) α)

(void must not be a free variable in β but this can be guaranteed by using gensym)

3 2020-02-11 10:48

>>1
You would have gotten more out of SICP if you had paid attention while reading it.
https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-12.html#%_idx_1062

The way this happens is that the let expression is interpreted as an alternate syntax for

((lambda (<var1> ...<varn>)
    <body>)
 <exp1>
 
 <expn>)

No new mechanism is required in the interpreter in order to provide local variables. A let expression is simply syntactic sugar for the underlying lambda application.

4 2020-02-11 18:43

>>3
Damn, everything that needs to be said has already been said in SICP. Did I forget that part or skimmed that brand new knowledge in the first chapter too fast? Either way, you're right, I should have paid more attention.

5 2020-02-13 20:13

Tell me Scheme is not dead and there's a future for it. I can't help reading about it but I have this awful feeling that I'm wasting my time because it's absolutely useless in the real world and that I should learn Javascript instead.

Who cares if a language is dead or not? You shouldn't learn scheme because you want to work with the language professionally (in fact that might even make it *less* fun to work with), but because you want to learn more about programming and computational thought on a more fundamental level.

6


VIP:

do not edit these