"stevan apter" <
apter@...> said:
> From: Mark van Gulik <ghoul6@...>
>> No, I don't want the closures to be named, and I also don't want them to be
>> lambda-like (i.e., taking named arguments, etc). I just want to be able to,
>> say, partially evaluate the "power" operation with the constant exponent 2
>> to produce a "squared" operation. Hm, bad example. How about use the
>> "power" operation and a constant exponent that's at a known position on the
>> stack to produce a new operation-data pair (a closure) that raises a passed
>> number to that exponent.
>>
>
> joy>[2 +] "plus2" is pop
>
> joy>10 plus2
> 12
The example you've provided isn't quite what I had in mind. You've bound
the *constant* 2 into the quotation. I was more interested in binding a
value that was passed at program construction time. Maybe something like
this (I'm not sure I have the syntax quite right)...
joy> [[+] cons] "adderOfN" is pop
joy> 1 adderOfN "increment" is pop
joy> 123 increment
124
In particular, I was looking for an idiom that was capable of capturing an
argument in a function, and dynamic program construction seems to be a
perfect fit. When there are many values to be captured, rather than splice
them into the exact points of use in the program, a single list can be
captured instead, and uses of these values can be via an index into the
list. As for my previous comments about a calling convention (I forget the
exact phrase I used) for capturing outer variables -- forget it. Program
construction is just too simple, and probably just as efficient, assuming
dynamic compilation deals with the basic idioms like this efficiently.