Dot notation and a crazy idea

Marcel Weiher marcel at system.de
Thu Mar 18 10:41:07 UTC 1999


> From: Bruce Cohen <cohenb at gemstone.com>
>
> Marcel Weiher wrote:
>
> > > 1.  Establish Package.Name as an alternate form of global
reference.
> >
> > Sounds pretty neat.  As a matter of fact, why not make 'dot'
> > notation  generally acceptable for retrieving values from (nested) 
> > dictionaries and plain objects (via accessors)?  The Package.Name 
> > would then be just a special case of that mechanism.
> >
>
>  The idea of a general use of this notation for nested access is rather 
> elegant, IMHO.  There's bound to be an arg ... um "heated discussion" 
> about the syntax, "/" versus "." versus whatever, but that's rather 
> secondary to the question of having the functionality.  I prefer "." 
> myself, mostly because both ThingLab and the collection query direct 
> access syntax of GemStone Smalltalk use it.  Also, it may be just my 
> eyes, but I find it easier to read in a lot of the fonts I see in
> everyday work.

Yes, the more I think about it, the more I like the idea, especially  
after reading the ThingLab docs.  I hadn't really considered the
positive implications for access control and change management.

It could also make the intentions of message sends much clearer by
syntactically distinguishing between gathering the participants and  
sending the message.

	customer name capitalize.
vs.
	customer.name capitalize

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

<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 :-)





More information about the Squeak-dev mailing list