AW: [squeak-dev] IdentitySet>>collect:

Eliot Miranda eliot.miranda at gmail.com
Thu Nov 27 00:51:25 UTC 2014


On Wed, Nov 26, 2014 at 4:31 PM, David T. Lewis <lewis at mail.msen.com> wrote:

> It seems to me that Object>>species is intended to handle this sort of
> issue.
>

You're right.  That's what it's there for.

For IdentitySet, it answers what Eliot was expecting:
>
>    IdentitySet new species ==> IdentitySet
>    Set new species ==> Set
>
> However, IdentitySet>>collect: does not make use of this, and it answers
> a Set for the reasons that Levente explained.
>
> Answering an Array or and OrderedCollection would not really make sense,
> because sets are unordered collections (but Bag might be better).
>
> Shouldn't we have an implementation of IdentitySet>>species that answers
> Set (or Bag), with a method comment explaining why this is the case, and
> with all of the collection methods using #species to answer the right
> kind of result?
>
> I note that IdentitySet>>collect: answers a Set, but IdentitySet>select:
> sends #species and therefore answers an IdentitySet.
>
> So I think that if we want the #species of an IdentitySet to be a Set,
> then we should make it so, and give it a method comment to explain the
> rationale. And the #collect: and #select: methods should both answer a
> result of that #species.
>

+1


> Dave
>
>
> On Thu, Nov 27, 2014 at 01:14:30AM +0100, Levente Uzonyi wrote:
> > Your example hides the problem of ordering - what Tobias is asking about
> -
> > so here's another:
> >
> > (IdentitySet withAll: #(1 1.0)) collect: [ :each | each class ]
> >
> > If IdentitySet >> #collect: were returning an Array, then what would be
> the
> > answer?
> >
> > { SmallInteger. Float } or { Float. SmallInteger } ?
> >
> > If you really want to have the resulting collection have the same size,
> > but avoid the problem with ordering, then what you really need is a Bag.
> > Luckily you can have whatever you want (as long as it makes sense):
> >
> > (IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as:
> Set.
> > "==> a Set(1)"
> > (IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as:
> > IdentitySet.
> > "==> an IdentitySet(1)"
> > (IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as:
> > Array.
> > "==> #(1 1)"
> > (IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as:
> > OrderedCollection.
> > "==> an OrderedCollection(1 1)."
> > (IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as:
> Bag.
> > "==> a Bag(1 1)"
> > (IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as:
> > IdentityBag.
> > "==> an IdentityBag(1 1)"
> > (IdentitySet withAll: #(1 1.0)) collect: [ :each | each asInteger ] as:
> > Heap.
> > "==> a Heap(1 1)"
> >
> > Levente
> >
> > On Thu, 27 Nov 2014, Frank Lesser wrote:
> >
> > >Hi Tobias,
> > >agree, a problem of "OrderedCollection"
> > >not to break a lot of other things we could return an Array.
> > >but for me collecting has priority.
> > >Frank
> > >
> > >-----Urspr?ngliche Nachricht-----
> > >Von: squeak-dev-bounces at lists.squeakfoundation.org
> > >[mailto:squeak-dev-bounces at lists.squeakfoundation.org] Im Auftrag von
> > >Tobias
> > >Pape
> > >Gesendet: Donnerstag, 27. November 2014 00:48
> > >An: The general-purpose Squeak developers list
> > >Betreff: Re: [squeak-dev] IdentitySet>>collect:
> > >
> > >
> > >On 27.11.2014, at 00:34, Frank Lesser <frank-lesser at lesser-software.com
> >
> > >wrote:
> > >
> > >>hmm, not convinced
> > >>
> > >>(IdentitySet withAll: #(1 1.0)) collect: [:e| e asInteger ]
> > >>OrderedCollection(1 1 )
> > >>
> > >>in LSWVST ( one-to-one ), you collect results of evaluating a block on
> > >>objects.
> > >>
> > >>Frank
> > >>maybe I am wrong ...
> > >
> > >Where would the order come from for that _Ordered_Collection?
> > >
> > >Best
> > >     -Tobias
> > >
>
>


-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20141126/b42f2c2c/attachment.htm


More information about the Squeak-dev mailing list