Will squeak ever support compile-time evaulation?

Lex Spoon lex at cc.gatech.edu
Wed Feb 13 16:01:03 UTC 2002


Hans-Martin Mosner <hmm at heeg.de> wrote:
> Chris Muller wrote:
> 
> > VisualAge supports a non-standard Smalltalk syntax
> > element for compile-time evaluation of methods, useful
> > for balancing intention-revealing code and
> > performance.  For example:
> > 
> > bitMultipliers
> >   ^##((1 to: 128) collect: [ :factor | (256 raisedTo:
> > factor) - 1 ])
> > 
> I see no big advantage over class variable initialization


The main advantages are, I believe:
	
	1. The item is defined right where it's used.

	2. You don't have to name it.

Even though it's wonderful to be able to name things and to move them
somewhere else, sometimes it's just as wonderful not to have to.  :)

For example, suppose you are implementing the quadratic formula:

	discriminant := b*b - (4*a*c).
	solution1 := (b negated + dicsriminant sqrt) / (2*a).
	solution2 := (b negated - dicsriminant sqrt) / (2*a).


It's one thing to explicitly name "discriminant": there is an existing
name for it, and there are benefits to having this concept available
(e.g., now you can write "discriminant < 0 ifTrue: [...]").  But what
about the 2*a term, or the 4*a*c term?  What would you even call them,
if you decided (or the system forced you) to give them names?  I think
it's pretty clear that putting the 2*a and the 4*a*c directly inline
makes it easier to think about.

For a more down-to-earth example, would it help a millipede to think
about each leg individually?


Anyway, the naming issue is the main reason I'd like to have such a
feature.  But, I'd probably vote to leave it out, as well:  I don't seem
to run into it very frequently, and it does add new difficulties.


-Lex



More information about the Squeak-dev mailing list