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

Re: let and for vs. lambda variations



Harald> Actually, even the multiple binding forms can be rewritten as lambdas,
Harald> using the wrapping trick, but it would be awkward and require some
Harald> obfuscated code:
Harald> ....
Harald> where `xy' is a symbol that does not appear in the text of cmd.  (!)

Paul> which is not possible to determine in es, given that you can write
Paul> 	`{ echo -n x; echo -n y } = foo
Paul> in es.  hence my comment about it not being possible.

Again, I have been careless.  But this has got to be right:

  let (x=a b; y=c d) cmd --> 
  @ curried-body x y {<={$curried-body <=$y} <=$x} \
    @ x {$&result @ y {cmd}} <={wrap x} <={wrap y}

Note that I am intentionally reusing the variables x and y, making the
code harder to read but easier to generate automagically.
Here is an experiment validating it, handtranslating

let (x=new x; y=$x) {echo inner x: $x \ninner y: $y}

; x = old x
; @ curried-body x y {<= {$curried-body <=$x} <=$y} \
    @ x {$&result @ y {echo inner x: $x \ninner y: $y}} \
    <={wrap new x} \
    <={wrap $x}
inner x: new x 
inner y: outer x
;

So indeed it can be done, given sufficient will and care.

Note that I am not necessarily saying it *should* be done, but let us
at least be clear on what is possible and what is not, and how hard it
is to do the possible things, before we reject them.

- Harald