Polymorphism without protocol dilution

Maurice Rabb m3rabb at stono.com
Wed Aug 26 04:39:12 UTC 1998


I would appreciate any thought on the following:

I though I would add the common method #at:ifAbsentPut: to Dictionary.

As the convention varies between dialects, I though it would be useful for
the 'ifAbsentPut: parameter' to accept either a value, or a block to be
evaluated.

My first iteration was:

at: key ifAbsentPut: valueObject
    ^self at: keyObject ifAbsent: [self at: key put: valueObject value]

For this to work would require that I add Object>>#value which I remember
is a no-no, because it dilutes the BlockContext protocol as Object>>#do:
diluted the Collection protocol.  We replaced Object>>#do: with #in:, so
with what do we replace Object>>#value?

Two sets of solutions come immediately to mind:
1)
BlockContext>>#selector1
   ^self value

Object>>#selector1
   ^self

at: key ifAbsentPut: valueObject
   ^self at: key ifAbsent: [self at: key put: valueObject selector1]

selector1 could be one of the following:
a) evaluate
b) evaluated
c) simplify
d) simplified
e) asValue
f) asValueObject
g) asEvaluated
h) asEvaluatedObject
i) asImmediate
j) asImmediateObject

2)
BlockContext>>#selector2
   ^self

Object>>#selector2
   ^[self]

at: key ifAbsentPut: valueObject
   ^self at: key ifAbsent: [self at: key put: valueObject selector2 value]

selector2 could be one fo the following:
a) asBlock
b) asBlockContext
c) asAction

Of my suggestions I prefer set 1 over 2 because set 2 seems more
circuitous.  Of set 1 I prefer option e.  Unfortunately, asValue is already
used in other dialects to convert an Object to a ValueHolder/ValueModel.  I
wish they uses asValueModel (or stuck with ValueModel on: anObject)
instead.

As far as names go I often wish some of the more fundamental methods were
better named so that I could use the name which they currently occupy for
something more appropriate (IMHO).

Which technique and selector name is recommended?

--Maurice

---------------------------------------------------------------------------
  Maurice Rabb    773.281.6003    Stono Technologies, LLC    Chicago, USA





More information about the Squeak-dev mailing list