Question

I'm playing w/ adding a little currying stuff to BlockClosure.

To have it done dynamically (ie. not hardcoding all the cases for different number of arguments of the original block) I'd need to construct BlockClosures dynamically, in order to pass the varying number of arguments.

Is there a way to do it, even if it involves some kind of dynamic eval/compile?

Was it helpful?

Solution 2

Is the following what you are lookig for? In a workspace try:

|myBlock|
myBlock := Compiler evaluate: '[ 1 + 2 ]'.

Now you have compiled a block from a string:

myBlock class -> BlockClosure

and can evaluate it:

myBlock value -> 3

OTHER TIPS

Have a look at this articles by Vassili Bykov:

Especially as i understood your question was about the varying number of arguments:

However, since Smalltalk blocks don’t support the equivalent of Lisp “rest” arguments, the curriedWithArguments: method would have to explicitly enumerate and handle all arities we realistically expect to use in block invocations. Using CurriedBlock instead produces a nicer example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top