Multiple Returns, was Re: Common Lisp style macros inSmalltalk?

Lex Spoon lex at cc.gatech.edu
Wed Jan 19 05:16:58 UTC 2000


Dan Ingalls <Dan.Ingalls at disney.com> wrote:
> >On Tue, Jan 11, 2000, agree at carltonfields.com wrote:
> >[...]  
> >> The "strict" Smalltalkologist might observe (and it has been
> >> observed many times in these letters), that the proper
> >> methodological solution is that every such aggregating should have
> >> its own aggregating class.  Thus:
> >> 
> >> 	^ Foo with: expresion1 with: expression2 with: expression3.
> 
> Chris Reuter <cgreuter at calum.csclub.uwaterloo.ca> replied:
> >I would think that creating a new class just to return multiple
> >objects is overkill unless the class is also needed to do something
> >more.  What's the rationale for doing this rather than just returning
> >an array?
> 
> Just to keep this topic from dying, it would be fun (maybe it has been done already) to create a class of named tuples, where you could say,
> 
> 	^ Tuple voltage: 220 current: 7.5 startingTorque: 185
> 
> This would intercept messageNotUnderstood: on the first go-round, and create a simple subclass with three fields named, uh, 'voltage', 'current', and 'startingTorque', and with the appropriate creation and access methods.
> 
> It could all run about as fast as arrays, but be clearer, and not require any extra classes in the "library", as all such examples would be created on the fly as needed.
> 

Wow, this is cool.  The brief time that I used Lisp was enough to
impress upon me how nice it is to just whip up new data structures as
you need them.  It sucked, though, that these data structures could
never really be defined anywhere; you were on your honor to keep it
straight.  And if you later abstracted the structure behind function
calls, you had a lot of work to do in the refactoring.

This Tuples proposal seems to offer a good compromise.  You can use the
Tuples while developping, and then easily refactor the auto-generated
class into something cleaner once you have your design nailed down.  In
particular, this helps you avoid the drag of having to do all this for
some petty new kind of object you suddenly need:

	- think of a good name
	- define the class
	- write all the initializer code
	- write accessors


Furthermore, the after-the-fact refactoring should be pretty simple,
because everyone is already using nice objecty message sends to access
the Tuple.  To contrast, if you use array's, then you have to dig up and
fix things like "x at: 2".

So, I think it sounds neat.  Has anyone worked in such a system before? 
Doesn't Smalltalk/X have a way to define simple classes without using
the browser?  I wonder how it compares.

Lex





More information about the Squeak-dev mailing list