Why we should remove {} from Squeak

Richard A. O'Keefe ok at atlas.otago.ac.nz
Mon Oct 1 05:00:06 UTC 2001


"David N. Smith (IBM)" <dnsmith at watson.ibm.com> pointed out:
	HeadMorph>>addSpikyHair
		| hair |
		hair _ PolygonMorph
			vertices:  {83 at 3.  81 at 30.  91 at 27.  111 at 23.
				    97 at 32.  112 at 37.  99 at 45.  114 at 52. ... }

Anyone who wants to simplify the parser by eliminating {...} could simplify
it still further by eliminating #(...) as well.  After all, #(...) can be
eliminated just like {...}.

It has always seemed a shame that there was no way to get a Point into a
literal array.  It could be done:  where <number> is allowed, allow
<number>@<number>.  That would be a special case, but the whole of #(...)
is a special case.
	
I agree that {...} is useful.

{e1. ... . en} is equivalent to
    (OrderedCollection new "note no semicolon"
     add: (e1);
     ...
     add: (en);
     asArray)
so it obviously CAN be eliminated.  That doesn't mean it should be.
#@ can be eliminated too:  aNumber @ anotherNumber is equivalent to
Point x: aNumber y: anotherNumber.  That doesn't mean #@ should be
eliminated.

The practical questions are
 - would eliminating this feature save more code in the parser and elsewhere
   than it would cost in all the code using it (remember, not all such code
   is known to SqC or anyone else)

 - is ideological purity worth the loss of clarity?

 - would it be feasible to make {} support a module?

	At 8:49 +0200 9/30/01, ducasse stephane wrote:
	>#() is necessary because it is compiled statically and cannot not be
	>simulated by other construct. Storing #() in Stack frame is not really goo
	>but this is an implementation aspect.
	
This is false.  Any use of # can be eliminated by adding a class variable
and a class method using lazy initialisation.  For example,
	   #( abc 'abc' 4  3.4  $r )
	
can be written as 
	MyClass literal27
where
	MyClass class>>literal27
	    literal27 ifNil: [
		literal27 := (OrderedCollection new
		    add: 'abc' asSymbol;
		    add: 'abc';
		    add: 4;
		    add: 3.4;
		    add: $r;
		    asArray)].
	    ^literal27

Come to think of it, we could eliminate $r and 'abc' too:
'abc' is (String fromPacked: 6382179) allButFirst
$r    is Character value: 114.

So
	#(abc 'abc' 4 3.4 $r)
can, by reductio ad absurdum, be replaced by
	
	MyClass class>>literal27
	    literal27 ifNil: [
		literal27 := (OrderedCollection new
		    add: (String fromPacked: 6382179) allButFirst asSymbol;
		    add: (String fromPacked: 6382179) allButFirst;
		    add: 4;
		    add: 3.4;
		    add: (Character value: 114);
		    asArray)].
	    ^literal27

without any non-numeric literals at all.

This is hardly less ridiculous than removing {}.




More information about the Squeak-dev mailing list