Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating BlockClosures dynamically?

I'm playing with 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?

like image 383
Wojciech Kaczmarek Avatar asked Jan 27 '26 23:01

Wojciech Kaczmarek


1 Answers

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
like image 137
MartinW Avatar answered Jan 29 '26 11:01

MartinW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!