Hey there, I' ve been thinking about possible implementations for adding curryfication to block closures. Here's how it �would be used, following by the implementation.�
addBinary := [:p1 :p2 | p1 + p2] .
add3 := addBinary curry: 3.
add3 curry: 5.�
8
BlockClosure >> curry: aParameter
(numArgs = 0)�
ifTrue: [Error signal.].
(numArgs = 1)�
ifTrue: [^ self value: aParameter.].
(numArgs = 2)�
ifTrue: [
^ [:p1 | self value: aParameter value: p1]
].
(numArgs = 3)�
ifTrue: [
^ [:p1 :p2 | self value: aParameter value: p1 value: p2]
].
(numArgs = 4)�
ifTrue: [
^ [:p1 :p2 :p3 | self value: aParameter value: p1 value: p2 value: p3]
].
Yes, I know the implementation works only for a fixed number of arguments. Any ideas on how to dynamically create a block with an arbitary number of parameters.? Maybe creating the source code string and compiling it?
Basically I 'd like to create this block :
^ [:p1 .. :pn �| self value: aParameter value: p1 �... value: pn ]
Thanks, Seba