[Cuis-dev] curried blocks

Mariano Montone marianomontone at gmail.com
Sat Aug 3 10:29:17 PDT 2024


Cuis includes an implementation already.

Have a look at BlockClosure>>withFirstArg:

https://en.wikipedia.org/wiki/Partial_application

     [ :a :b | a + b ] value: 1 value: 2
     [ :a :b | a + b ] withFirstArg: 1
     ([ :a :b | a + b ] withFirstArg: 1) value: 2
     ([ :a :b | a + b ] withFirstArg: 1) withFirstArg: 2
     (([ :a :b | a + b ] withFirstArg: 1) withFirstArg: 2) value

     ([ :a :b | a - b ] withFirstArg: 1) value: 2.


Yours supports more arguments, though; you could try adding a 
#withPartialArgs: to BlockClosure if #withFirstArg: is not enough in 
your opinion.


     Mariano


El 2/8/24 a las 20:53, Mark Volkmann via Cuis-dev escribió:
> I wanted to see if it was possible to define a class that supports 
> partial application with blocks. The goal is to be able to pass fewer 
> arguments than a block requires and get back a new "block" that 
> requires the remaining arguments. Perhaps this has already been done 
> and I just didn't find it.
>
> Here are examples of using my solution:
>
> cb := CurriedBlock block: [:a :b | a + b].
> cb valueWithArguments: #(2 3). "5"
>
> cb2 := cb valueWithArguments: #(5). "a new CurriedBlock"
> cb2 valueWithArguments: #(7). "12"
>
> I attached my solution as a fileOut. I'd love to get some feedback in 
> terms of style and better ways to implement it. What would you do 
> differently?
>
> -- 
> R. Mark Volkmann
> Object Computing, Inc.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240803/cf0a15e7/attachment.htm>


More information about the Cuis-dev mailing list