There's no way you could use an integer (or any  number) as a selector.

So what you can do if you want to avoid using the "wordy" #value: selector
is to implement your own selector in BlockClosure.

It could be a #v: selector (so it is still a keyword selector) or a symbol
such as #<< that ends up calling #value:, but keep in mind that if you use
a symbol you cannot extend it to have more than one parameter.

Regards,



El mié., 23 de octubre de 2019 09:22, main <johan_forsberg...@hotmail.com>
escribió:

> Hello fellow Pharoians (?) from a lonely Swede.
>
> I just found out about Pharo (and Smalltalk) two days ago and I'm already
> loving it :)
> However, there is a behavior I would like to change, or be enlightened
> about
> how it could be done.
>
> As I understand it (bear with me) BlockClosure from Kernel-Methods does not
> understand (by default?) how to respond to an "anonymous object" (no
> message
> name).
>
> Is there any way this could be implemented? I'll post an example soon
> (I currently use both Pharo 7 and 8)
>
> If I write the following:
>
> [:x | x + 1] value: 3
>
> and evaluate it, I get the expected result, which is 4.
>
> That's nice.
>
> What I would really like is to be able to just send 3 to BlockClosure and
> make it repond as above.
>
> Like this:
>
> [:x | x + 1] 3
>
> or like this:
>
> 3 [:x | x + 1]
>
> Would this be possible?
>
> -----------------------
>
> Also as a bonus, would it be possible to use this for "function
> composition", "Block composition" or similar?
>
> Example of composition:
>
> [ :f :g | [ :x | f value: (g value: x) ] ]
>
> I could use this construct like this for example:
>
> (([ :f :g | [ :x | f value: (g value: x) ] ])
> value: [:x | x + 1]
> value: [:x | x - 1])
> value: 5
>
> But… It's a bit wordy.
>
> What I would like to be able to do (essentialy remove "value:"):
>
> (([ :f :g | [ :x | f (g x) ] ])
> [:x | x + 1]
> [:x | x - 1])
> 5.
>
> Or in one line:
> (([ :f :g | [ :x | f (g x) ] ]) [:x | x + 1] [:x | x - 1]) 5.
>
> While this might seem obscure, I would really find it useful.
>
> Can it be done?
>
> Thanks in advance
>
>
>
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>
>

Reply via email to