[squeak-dev] [Discussion] Creating message sends via anObject >>> #selector ?

Jakob Reschke forums.jakob at resfarm.de
Wed Jun 12 16:08:53 UTC 2019


Java has had this as :: since the introduction of lambdas in Java 8. It is
a shortcut replacement for trivial lambdas to omit the argument names.

In JavaScript or Python you can just pass around the bound methods as
callables. Smalltalk does not have attribute/method access syntax (self.xyz)
to make it work naturally in the same way (meaning it would look
special/unfamiliar).

Moreover, this would look awful for messages with more than one argument.
The other languages don't suffer from that because they suffer from prefix
notation for message sending. ;-)

I think the original block is concise enough and does not make you wonder
what it means and how it works (unless you don't know blocks and the
Collection protocol).

Marcel Taeumel <marcel.taeumel at hpi.de> schrieb am Mi., 12. Juni 2019, 15:31:

> Hi, there.
>
> One of our students was curious about whether the following expression
> could be somehow improved:
>
> *someObjects collect: [:each | self convert: each].*
>
> I suppose that the main goal was to remove the brackets. Similar to the
> existing symbol shortcut:
>
> *someObjects collect: #message.*
>
> Looking at all implementors of #value:, #cull: and alike, I suppose that a
> more convenient creation of a MessageSend could tackle this case directly:
>
> *someObjects collect: self >>> #convert:.*
>
> This feels strange. :-) Very strange. But maybe it's just me. I don't see
> the traditional [:each | ...] version as neither difficult to read nor
> write.
>
> What do you think about adding the #>>> message to MessageSend for more
> compact instantiation? Do you see other scenarios of interest? Would it be
> just superfluous? Producing less readable code?
>
> Best,
> Marcel
>
> P.S.: #>>> would be close to #>>, which is implemented on Behavior to
> access method objects.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190612/b6115aab/attachment.html>


More information about the Squeak-dev mailing list