[ENH] Comma concatenation for Object

Richard A. O'Keefe ok at cs.otago.ac.nz
Mon Dec 9 01:36:48 UTC 2002


Brent Pinkney <brent_pinkney at yahoo.co.uk> wrote:
	It is possible to concatenate Collections together
	using the #, method.
	
No, it is only possible to concatenate SequenceableCollections.

You can also concatenate sounds.

Applied to ExceptionSets and Exception classes (but not Exception
instances), comma basically means "union".  Actually, it's worse
than that.  In Squeak 3.2, ExceptionSet >>, is basically #add:,
which makes it as unlike concatenation as it could be.  

	However, if the receiver or args are not Collections
	this is a DNU.
	
As noted above, not true.

	Since Object>>#asArray already exists,
	Object>>#, should also be included.
	
There's a fairly big gap in logic here.

To start with, in Squeak 3.2, Object>>asArray does NOT exist.
Only {Array,Array2D,B3DActiveEdgeTable,Collection,CompositeEvent,
SequenceableCollection}>>asArray.

Next, if it DID, perhaps that would only mean that it shouldn't.

And if it did and should, the hypothetical existence of Object>>asArray
would no more imply that Object>>, should exist than the actual
existence of Set>>asArray (inherited from Collection>>asArray) implies
that Set>>, should exist.

	e.g.
	      5, 6      ---> #(5 6)
	      5, #(6 7) ---> #(5 6 7)
	      #(6 7), 8 ---> #(6 7 8)
	
I've thought of this myself.  It's an obvious thing to think of.
But if you then ponder it just a _little_ bit more, it becomes
obvious that it's incoherent.

If 5, 5 => #(5 6)
then why doesn't #(5), #(6)) => #((5) (6))?
For ExceptionSets, it sort of makes sense, because ExceptionSets
cannot contain ExceptionSets.  But Arrays *can* contain Arrays.

To get the effect of			use this in Squeak
m, n					{m. n}
m, s					{m} , s
s, n					s , {n}
where m, n are expressions that yield non-sequences,
and s is an expression that yields a sequence.

Note also that the idea of having 5, 6 => #(5 6) is extremely
restrictive.  We're better of with SomeClass with: 5 with: 6
because then we can have any suitable class we want.

For the case of adding an element at the front or rear of an
existing sequence, we already have copyWith: which does the
add-at-rear version, so we could coherently do this:

  SequenceableCollection>>
    copyWithFirst: newElement
      ^self copyReplaceFrom: 1 to: 0 with: newElement
    copyWithLast: newElement
      ^self copyReplaceFrom: self size + 1 to: self size with: newElement

so
    s copyWithFirst: m  => ({m} as: s class) , s
    s copyWithLast: n   => s , {n}





More information about the Squeak-dev mailing list