[squeak-dev] The Inbox: Collections-ct.962.mcz

christoph.thiede at student.hpi.uni-potsdam.de christoph.thiede at student.hpi.uni-potsdam.de
Tue Nov 16 13:36:25 UTC 2021


Hi Marcel, hi Tobias,

I would rather call it a coincidence that this constructor takes the same format as we use internally in the Bag. Maybe we should rename this into something like #newFromCounts:?

For a real use case, I use my new BenchmarkSimulator to count primitive calls and end up with a dictionary primitiveCounts that maps primitive numbers to counts. I think this is a valid use case and deserves its own protocol. Otherwise, I would need to do something like this:

	primitiveCounts := Dictionary new at: 6 put: 2; at: 7 put: 1; at: 61 put: 17; yourself.
	(primitiveCounts associations collect: [:assoc | Array new: assoc value withAll: assoc key]) flatten as: Bag

Which really feels a bit cumbersome. :-)

Best,
Christoph

---
Sent from Squeak Inbox Talk

On 2021-11-16T12:04:54+01:00, marcel.taeumel at hpi.de wrote:

> > That contents is a dict is implementation detail not to be leaked.
> 
> To be fair, there is an actual extension point in #contentsClass. Yet, it remains an implementation detail, hidden from clients. Clients should use #newFrom: or #withAll: to fill a bag with existing contents.
> 
> Best,
> Marcel
> Am 16.11.2021 11:58:09 schrieb Tobias Pape <das.linux at gmx.de>:
> -1
> 
> this is to my eyes doubtlessly private :)
> That contents is a dict is implementation detail not to be leaked.
> 
> Best regards
> -Tobias
> 
> > On 16. Nov 2021, at 11:28, Marcel Taeumel wrote:
> >
> >> ==================== Summary ====================
> >>
> >> Name: Collections-ct.962
> >> Author: ct
> >> Time: 13 November 2021, 2:29:12.457577 am
> >> UUID: 762c672f-abb5-194e-9f54-14cce19aa7f9
> >> Ancestors: Collections-pre.961
> >>
> >> Adds convenience constructor to Bag.
> >>
> >> Bag newFromContents: (Dictionary new at: #mon put: 7; at: #tue put: 2; at: #wed put: 4; yourself).
> >>
> >> =============== Diff against Collections-pre.961 ===============
> >>
> >> Item was added:
> >> + ----- Method: Bag class>>newFromContents: (in category 'instance creation') -----
> >> + newFromContents: aDictionary
> >> +
> >> + ^ self new setContents: aDictionary!
> 
> 
> 
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211116/ee077bd0/attachment.html>
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211116/304b8655/attachment.html>


More information about the Squeak-dev mailing list