Dot notation and a crazy idea
Bruce Cohen
cohenb at gemstone.com
Thu Mar 18 20:41:45 UTC 1999
Marcel Weiher wrote:
> In fact, a slightly extended version would pretty much solve the
> syntactic difficulties I had with my ideas for sending messages to
> multiple objects:
>
> customers do : [ :each | each name capitalize ].
> vs
> customers each name capitalize do " or other variants
> vs
> customers.each.name capitalize
> or
> customers.*.name capitalize
>
The "*" notation is a part of the GemStone syntax. I should have mentioned
it in my previous message about the "O-O-ness" of dot notation, as a reason
why breaking encapsulation is sometimes highly desirable. Although, again,
there's a way of presenting this as a generalization of message sends rather
than as internal instvar access, using your "crazy idea".
>
> <crazy-idea>
>
> In fact, the whole business of refering to objects via name is
> really just a special case of selection. Which object do you want?
> The one named 'bert'.
>
> Let's generalize this back to saying that a dotted name is really a
> select statement. So we could have something like:
>
> customers.[ name == 'Kay' ].name capitalize.
>
> instead of
>
> customers select: [ :each | each name == 'Kay' ] do: [ :each
> | each name capitalize ].
>
> with the square-brackets thingy in the dotted path being a
> simplified block, though maybe a full block would be better. (Then
> again, why shouldn't both types co-exist?)
>
> Add multiple method returns ( 'sendback' ), and ... wow! Certainly
> all sorts of 'generate-and-test' programs become one-liners.
>
> </crazy-idea>
>
> Marcel
>
> p.s.: Yeah, I know, it was all implemented in Smalltalk-72 and only
> taken out later :-)
I like it. It makes the "map" functionality of select, which I admire
greatly, much easier to read and write.
Bruce Cohen
More information about the Squeak-dev
mailing list
|