[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Semantics of let



I have noticed that
   let (a=1;b={a=2}) {$b; echo $a}
prints 2, i.e. it is equivalent to
   let (a=1) { let (b={a=2}) {$b; echo $a} }
In other words, es's let is like Scheme's let*.

Actually, the experiment is consistent with let being like letrec, but
   let (b={a=2};a=1) {$b; echo $a}
prints 1, so that's not it.

I presume this is intentional but can't see any mention of it in the
documentation.  Can I expect this behaviour to last in future versions?

And what will (read: should)
   let ((a b)=1 {a=2}) {$b; echo $a}
print, when multiple assignments are added to the language?

By the way, I had some fun figuring out how to do the Y combinator:

; fn Y f {@ g {$g $g} @ h {$f {$h $h}}}
; foo = <={Y @ r {
           result @ x {
             if {~ $#x 0} {result nice!} {echo $x; <=$r $x(2 ...)}}}}
; echo <={$foo a b c}
a b c
b c
c
nice!
; 

Figuring out the fact that I had to use <=$r to recurse cost me a bit
of time, to be honest...  8-)

- Harald