[squeak-dev] The Trunk: Collections-eem.756.mcz
Tobias Pape
Das.Linux at gmx.de
Thu Jun 15 20:22:22 UTC 2017
> On 15.06.2017, at 21:40, Eliot Miranda <eliot.miranda at gmail.com> wrote:
>
> Hi Tobias,
>
> On Thu, Jun 15, 2017 at 12:32 PM, Tobias Pape <Das.Linux at gmx.de> wrote:
>
> > On 15.06.2017, at 21:22, Chris Cunningham <cunningham.cb at gmail.com> wrote:
> >
> > #testMissingThenAdd: ?
> >
>
> #isAdding:
> #ingests:
>
> #wasAbsentButNowIsPresent:
>
> (just rambling…)
>
> I like added:. Its concise, accurate and reads nicely:
Ok, but then maybe #addedNew: ? So as we know more than just an adding operation succeeded… :)
>
> withoutDuplicates
> "Answer a copy of the receiver that preserves order but eliminates any duplicates."
> | seen |
> seen := Set new: self size.
> ^self select: [:each| seen added: each]
>
> messagesDo: aBlock
> "Evaluate aBlock exactly once with all the message selectors sent by me."
>
> | scanner aSet |
> self isQuick ifTrue: [ ^self ].
> scanner := InstructionStream on: self.
> scanner scanFor: [ :x |
> | selector |
> (selector := scanner selectorToSendOrSelf) == scanner ifFalse: [
> ((aSet ifNil: [ aSet := IdentitySet new ]) added: selector) ifTrue: [
> aBlock value: selector ] ].
> false "keep scanning" ]
>
>
>
> > On Jun 15, 2017 12:19 PM, "Eliot Miranda" <eliot.miranda at gmail.com> wrote:
> > Hi Tobias,
> >
> > On Thu, Jun 15, 2017 at 12:06 PM, Tobias Pape <Das.Linux at gmx.de> wrote:
> >
> > > On 15.06.2017, at 20:30, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> > >
> > > Hi Levente, Hi Chris,
> > >
> > > On Wed, Jun 14, 2017 at 1:10 PM, Levente Uzonyi <leves at caesar.elte.hu> wrote:
> > > On Wed, 14 Jun 2017, commits at source.squeak.org wrote:
> > >
> > > Eliot Miranda uploaded a new version of Collections to project The Trunk:
> > > http://source.squeak.org/trunk/Collections-eem.756.mcz
> > >
> > > ==================== Summary ====================
> > >
> > > Name: Collections-eem.756
> > > Author: eem
> > > Time: 14 June 2017, 11:03:24.917631 am
> > > UUID: 8d7c03bc-1cdb-44c7-9173-10d50c0dae29
> > > Ancestors: Collections-eem.755
> > >
> > > Add SequenceableCollection>>withoutDuplicates for a more elegant fix to MailMessage>>to:
> > >
> > > =============== Diff against Collections-eem.755 ===============
> > >
> > > Item was added:
> > > + ----- Method: SequenceableCollection>>withoutDuplicates (in category 'copying') -----
> > > + withoutDuplicates
> > > + "Answer a copy of the receiver that preserves order but eliminates any duplicates."
> > > + | seen |
> > > + seen := Set new: self size.
> > > + ^self select: [:each|
> > > + (seen includes: each)
> > > + ifTrue: [false]
> > > + ifFalse: [seen add: each. true]]!
> > >
> > > What a great opportunity to use #addNewElement::
> > >
> > > ^self select: [ :each | seen addNewElement: each ]
> > >
> > > I love the functionality but I don't like the selector. It seems to imply that one must only add a new element. So why not call this something like addIfAbsent: ?
> > >
> > > Here are some suggestions. Votes?
> > > - don't change it; stick with addNewElement:
> > > - addIfAbsent:
> > > - ifAbsentAdd:
> > > - ifMissingAdd:
> > >
> > > I think I prefer ifAbsentAdd: cuz addIfAbsent: looks too much like a potential spelling error, and conflicts with typical ifAbsent: arguments supplying exception blocks. But I could go with ifMissingAdd: because it is more distinctive.
> >
> > Well, we do have
> >
> > Collection>>addIfNotPresent:
> >
> > So why invent a new one?
> >
> > Because addIfNotPresent: answers its argument and we need one that answers whether the element was absent. So alas addIfNotPresent: is not a suitable candidate.
> >
> >
> > I think the important thing with #addNewElement: is that it returns *whether* it added a new element
> > but then again it breaks the tradition of #add* returning its argument…
> >
> > a very clear and very strange one that would reveal that a boolean is returned would be #isAbsentAndIfSoAdd: …
> >
> > wasAbsentAdding: or ifWasAbsentAdding: would be less cumbersome but I like something snappier that people will remember. ifMissingAdd: looks good because it doesn't conflict with the add*: methods answering their argument, and the ifMissing implies the answer is true if the element wasn't already present.
> >
> > Stéphane, can you live with ifMissingAdd: ? Chris?
> >
> > Best regards
> > -Tobias
> >
> > > _,,,^..^,,,_
> > > best, Eliot
> >
> > _,,,^..^,,,_
> > best, Eliot
>
> _,,,^..^,,,_
> best, Eliot
>
More information about the Squeak-dev
mailing list
|