>
> #(1 2 3) asDictionary
>
For this one, I would expect a dictionary with integer keys
I see a dictionary as an indexed collection with key that are not only integer
(like for an array).
1->1 2->2 3->3
I doubt this would be useful though.
My 2 cents,
Cédrick
This is exactly how I think and feel about bags. Thanks Richard.
Am .03.2019, 01:35 Uhr, schrieb Richard O'Keefe :
To me, a bag is first and foremost a multiset.
Yes, it's a collection, but it's not *just* a collection.
It's a very specific kind of collection with a very
salient
Handlingas: Dictionary
is really quite straightforward.
Add a one-line method to Bag:
Bag>>
associationsDo: aBlock
contents associationsDo: aBlock.
This is a good idea anyway, because currently there is a bug where
aBag associationsDo: aBlock
fails to pass Associations to aBlock. Once
To me, a bag is first and foremost a multiset.
Yes, it's a collection, but it's not *just* a collection.
It's a very specific kind of collection with a very
salient "characteristic function".
In my own Smalltalk library, #asDictionary isn't even *defined*
on things that are not dictionaries or
On Wed, Mar 6, 2019 at 10:25 AM Tim Mackinnon wrote:
> I still am tempted to make asDictionary work - because the the moment you
> get a #key , DNU error - which is definitely not right.
>
This argument gives me the willies. Sorry.
I can see an argument that a sequenceable collection can
I am still not convinced.
> On 6 Mar 2019, at 19:24, Tim Mackinnon wrote:
>
> I still am tempted to make asDictionary work - because the the moment you get
> a #key , DNU error - which is definitely not right.
The error might not be super clear, but it is not wrong, the elements of your
I still am tempted to make asDictionary work - because the the moment you get a
#key , DNU error - which is definitely not right.
So should Bag asDictionary give you a reasonable dictionary, or should it throw
a proper exception - something like:
DomainError signal: ‘#asDictionary not
And when asking the object:
#(1 2 4 5 6 7 2 1 4 3) asBag isDictionary
we get false. So, not, not a dictionary.
I still have been using #valuesAndCounts to get the dictionary out of a bag
on several occasions.
And is useful indeed.
#(1 2 4 5 6 7 2 1 4 3) asBag occurrencesOf: 2
and
#(1 2 4 5
I was just explaining how it is now, what I think the rationale is behind it.
I understand #asDictionary as working on a collection of pairs/associations
(because it basically goes to #withAll:).
A bag is just a collection that is optimised for many duplicates, the fact that
you have values
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
Doubtless the original poster expected aBag asDictionary
to answer a dictionary mapping the (distinct) elements of
the bag to their counts. Mathematically, a bag can
usefully be seen as a partial function from a set U to
the positive integers, and a dictionary with U keys and
positive integer
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: 'ABABAB'; valuesAndCounts.
> On 6 Mar 2019, at
I was surprised to find that a Bag can’t convert to a dictionary - e.g.
Bag new
addAll: 'aacddd’;
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:
13 matches
Mail list logo