[ENH] RBRelatedPatches [sm]

Richard A. O'Keefe ok at cs.otago.ac.nz
Wed Sep 17 07:21:32 UTC 2003


Ned Konz wrote:
	> at: #key ifAbsent: [ ] ifPresentDo: [ :v | ]
Avi Bryant <avi at beta4.com> replied:
	Yeah, I've wanted this one more than once.  Currently I resort to:
	
	val := dict at: #key ifAbsent: [].
	val ifNil: [...] ifNotNil: [...].
	
I wouldn't be either.
What if #key _is_ present in dict but is mapped to nil?

Am I the only person who finds that the use of #do: in the collection
classes has set up a mental expectation that ....Do: will be some kind
of loop?  Is there an intention-revealing word that could be used instead
of "Do" here that would not suggest loops to anyone?

We already have
    dict at: aKey ifAbsent: [ ]
and
    dict at: aKey ifPresent: [:v| ]
so a name which would fit the existing names in Dictionary would be
    dict at: aKey ifPresent: [:v| ] ifAbsent: [ ]

SkipList add: element ifPresent: aBlock
also takes a 1-argument block.

#ifPresent:ifAbsent: with the "present" block having 1 argument seems
to be the approach that is most consistent with existing stream methods.

Asymmetric?  Too right; it's *supposed* to be asymmetric.  In the one
case there's something you want and now have that you didnt' before,
in the other case there isn't.



More information about the Squeak-dev mailing list