[ENH] Message / Symbol / Block compatibility

Doug Way dway at mat.net
Wed May 26 06:50:20 UTC 1999


Just wanted to say that this is pretty cool.  Of the two methods
described, I prefer the Trampoline object because it can handle messages
with arguments succinctly.  For example:

| myNumbers |
myNumbers := #(6 4 1 3).

myNumbers select > 3.

myNumbers select between: 2 and: 5.

Now tell me that last one doesn't read like plain English!  (okay, it's
partly luck, but...)

I noticed one minor downside to the Trampoline versus the other methods,
which is that you can't pass messages to it which Object happens to
understand, such as 'asString'  (since the Trampoline uses
#doesNotUnderstand:).  I wonder if there's any way around that.

Also, if this ever gets fleshed out and to the point that it might be
considered as an addition to the base image, I'd probably go with just
adding one of these methods... Smalltalk usually avoids having several
very similar ways of doing the same thing.  But it's good to have them all
to play around with for awhile, though. :-) 

(Sorry, when I say "method" above I'm not referring to Smalltalk methods.)

- Doug Way
  EAI/Transom Technogies, Ann Arbor, MI
  dway at eai.com, dway at mat.net
  http://www.transom.com


On Sun, 23 May 1999, Marcel Weiher wrote:

> 
> I've added methods for #value: and #value:value: to both Symbol and
> Message to make them acceptable substitutes for blocks, especially in
> the #do:,#collect: etc. iteration methods. 
> 
> To rehash an old example, you can now say
> 
> 	 (1 to: 20) select:#odd. 
> or
> 	(1 to:20) select:(Message selector:#odd).
> 
> both without any additions to the collection classes.  The second
> example using a message object can be expressed more succinctly using
> some glue code and what I call a Trampoline (really a sort of higher
> order message): 
> 
> 	(1 to: 20) select odd.
> 
> #select returns the Trampoline object which captures the next message
> and immediately bounces it to its source. 
> 
> The next step will be extending this to handle messages with arbitrary
> numbers of variable arguments, such as
> 
> 	2 collect raisedTo:(1 to: 20) each.
> or
> 	(1 to:20) collect raisedTo:(1 to:20) each.
> 
> something my previous, unpublished approach did.  I feel that this new
> approach should achieve the same effect much more simply. 
> 
> Marcel





More information about the Squeak-dev mailing list