Search code examples
closuresmetaprogrammingsmalltalkpharocurrying

Creating BlockClosures dynamically?


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?


Solution

  • 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