[cl-faq] faq answer: Why are there both LET and LET*?

Luís Oliveira luismbo at gmail.com
Wed Jun 21 21:27:53 CDT 2006


Larry Clapp <larry at theclapp.org> writes:
> *** Why are there both LET and LET*?

Here are a few thoughts about this FAQ. Mostly little details.


> LET and LET* both calculate values and establish bindings.  They
> differ in when they do it.  LET calculates all values, and then
> establishes new bindings all at once, in parallel.  LET* binds each
> variable to a new value one at a time, serially.

"All at once, in parallel" might be misleading since there is a
"parallel let" that actually calculates the values in parallel, using
threads or whatever.


> This Lisp 
>
>   (let (a b c)	; ignore this for now
>     (setq a 1)
>     (setq b 2)
>     (setq c 3)
>     (let ((a 10)
> 	  (b (1+ a))
> 	  (c (1+ b)))
>       (format t "~D ~D ~D~%" a b c)))
>   prints=> 10 2 3
>
> is similar to this C
>
>   int a, b, c;
>
>   a = 1;
>   b = 2;
>   c = 3;
>
>   int tmp_a = 10;
>   int tmp_b = a + 1;
>   int tmp_c = b + 1;
>
>   a = tmp_a;
>   b = tmp_b;
>   c = tmp_c;
>
>   printf( "%d %d %d\n", a, b, c );

Hmm. I think using C is a bad idea here. For people that don't know C
perhaps a different notation would be better?

  a := 1
  b := 2
  ...

For people that know C, it might be confusing. A newbie might think
that, for example, (let (a b c) ...) is declaring uninitialized
variables and that accessing them before initialization would invoke
undefined behaviour.


> In fact, the * in LET* is sort of like the * in regular expressions:
> LET* means "multiple LETs".  See
> http://en.wikipedia.org/wiki/Regular_expression and
> http://en.wikipedia.org/wiki/Kleene_star.

Got any references on this? Is this really the origin of the name? I
thought the FOO* convention meant that it's a variation of FOO. (Hmm,
that'd would be a good FAQ, maybe.)

I second Pascal's suggestion about explaining LET* in terms of LET. Very
lispy. Another lispy detail about his example is that it returns the
values instead of printing them (let the pretty printer do that).

HTH

-- 
Luís Oliveira
luismbo (@) gmail (.) com
http://student.dei.uc.pt/~lmoliv/



More information about the cl-faq mailing list