Looks nice! Just my two cents. To make function comopostion work with multiple aruments, I implemented * as:
BlockClosure class>>* first ^ComposedFunction first: first second: self And use a dedicated class to make multiple arguments work: ComposedFunction>>value: arg ^second value: (first value: arg) ComposedFunction>>value: arg1 value: arg2 ^second value: (first value: arg1 value arg2) Then, we can write: [:x | x factorial ] * [:x :y | x + y] value: 1 value: 2 (I usually use the mathematical compostion operator, wich evalutes from right to left.) However, it is often convenient to interchange Symbols and Blocks, e.g., the above can be rewritten as #factorial * #+ value: 1 value: 2 That requires to implement the * operator on symbols, too. And depending on your Smalltalk implemenation, you may have to implement the evaluation protocol on symbols. Best, Steffen Am .10.2019, 15:12 Uhr, schrieb main <johan_forsberg...@hotmail.com>:
Hi again! Just putting it out there for anyone interested. What I did was define the following in Object: |> aBlock ^ [ :x | x => self => aBlock ] and also: => msg ^ msg value: self This enabled me to compose like this (I know I probably violate every rule in the book, whatever ): f := [ :x | x + 100 ]. g := [ :x | x + 20 ]. h := [ :x | x + 3 ]. 0 => (f |> g |> h). 123 Also tried using ~: 0 => (f ~ g ~ h). 123 It's just a matter of taste I guess, but for me it warms my heart -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html