As Richard said - as a bag is relationship between keys and frequencies, I would expect it to be able to convert to a dictionary. It displays in an inspector just like a Dictionary - which is why I figured I could convert to pass it back to the exercise that was written with Dictionaries in mind. The code to fix it is quite simple, but on these kinds of things - I thought it worth checking before submitting a PR. Tim
On 6 Mar 2019, at 13:53, Sven Van Caekenberghe <sven@stfx.eu> wrote:
Why would that work ? What would you expect the output to be ?
Try:
#(1 2 3) asDictionary
it fails in exactly the same way. You need key/value pairs (Associations).
These do work
Bag new add: #foo->100; asDictionary.
Bag new addAll: 'ABABABAAAA'; valuesAndCounts.
On 6 Mar 2019, at 14:25, Tim Mackinnon <tim@testit.works> wrote:
I was surprised to find that a Bag canât convert to a dictionary - e.g.
Bag new addAll: 'aabbbbcdddâ; asDictionary
Gives an error - Dnu #key
It looks to me like Bag is inheriting a bad version of #associationsDo: and instead could simply forward it to #doWithOccurences: instead?
I know Bag is not used that much - but it comes up a lot in programming exercises.
Tim