This has not changed since Smalltalk-80. Running Smalltalk-80 and
looking in the browser, I see
Dictionary>>
do: aBlock
super do: [:assoc | aBlock value: assoc value].
'super' here is Set, a Dictionary being implemented as a Set of
Associations (which was always a bad idea).
Dictionary>>do: has ALWAYS iterated over the elements of a dictionary,
NOT the associatons.
I have Squeak, Pharo, Smalltalk-80, VisuaWorks, VisualAe, Smalltalk/X,
and GNU Smalltalk (plus several others including my own).
They all follow the ANSI standard in this respect., The distinction
between #do: and #associationsDo: goes back to Smalltalk-80,
as does #keysDo:.
On Wed, 24 Jan 2024 at 05:33, Joachim Tuchel jtuchel@objektfabrik.de wrote:
So there we already have dialect differences …
Am 23.01.2024 um 17:32 schrieb James Foster via Pharo-users pharo-users@lists.pharo.org:
myDict associationsDo: [: anAssociation | ].
myDict keysDo: [:aKey | ].
myDict valuesDo: [:aValue | ].
myDict do: [:aValue | ]. “An alias for #valuesDo:”
James Foster
On Jan 23, 2024, at 8:27 AM, Joachim Tuchel jtuchel@objektfabrik.de wrote:
AI knows little about Smalltalk ;-)
You can use do: with each Association as a parameter or you can use keysAndValuesDo:
myDic do: [:assoc| | key value| key := assoc key. value := assoc value. ...].
myDic keysAndValuesDo: [:key :value| ...]
Joachim
Am 23.01.24 um 17:24 schrieb sergio ruiz:
I need to iterate over a dictionary.
I asked the AI buddy for a little help, and he says:
| myDictionary |
"Create a dictionary"
myDictionary := Dictionary new.
myDictionary at: 'one' put: 1.
myDictionary at: 'two' put: 2.
myDictionary at: 'three' put: 3.
"Iterate over the dictionary"
myDictionary do: [ :key :value |
Transcript show: key , ' -> ', value printString ; nl.
].
but when i try this, I get:
ArgumentsCountMismatch: This block accepts 2 arguments, but was called with 1 argument.
Is the AI using a different dialect of smalltalk?
how would I go about acting on each pair?
Thanks!
peace,
sergio
photographer, journalist, visionary
Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2
#BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
@sergio_101@mastodon.social
https://sergio101.com
http://www.codeandmusic.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101
--
Objektfabrik Joachim Tuchel mailto:jtuchel@objektfabrik.de
Fliederweg 1 http://www.objektfabrik.de
D-71640 Ludwigsburg http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1
This has not changed since Smalltalk-80. Running Smalltalk-80 and
looking in the browser, I see
Dictionary>>
do: aBlock
super do: [:assoc | aBlock value: assoc value].
'super' here is Set, a Dictionary being implemented as a Set of
Associations (which was always a bad idea).
Dictionary>>do: has ALWAYS iterated over the elements of a dictionary,
NOT the associatons.
I have Squeak, Pharo, Smalltalk-80, VisuaWorks, VisualAe, Smalltalk/X,
and GNU Smalltalk (plus several others including my own).
They all follow the ANSI standard in this respect., The distinction
between #do: and #associationsDo: goes back to Smalltalk-80,
as does #keysDo:.
On Wed, 24 Jan 2024 at 05:33, Joachim Tuchel <jtuchel@objektfabrik.de> wrote:
>
> So there we already have dialect differences …
>
> Am 23.01.2024 um 17:32 schrieb James Foster via Pharo-users <pharo-users@lists.pharo.org>:
>
> myDict associationsDo: [: anAssociation | ].
> myDict keysDo: [:aKey | ].
> myDict valuesDo: [:aValue | ].
> myDict do: [:aValue | ]. “An alias for #valuesDo:”
>
> James Foster
>
> On Jan 23, 2024, at 8:27 AM, Joachim Tuchel <jtuchel@objektfabrik.de> wrote:
>
> AI knows little about Smalltalk ;-)
>
> You can use do: with each Association as a parameter or you can use keysAndValuesDo:
>
> myDic do: [:assoc| | key value| key := assoc key. value := assoc value. ...].
>
> myDic keysAndValuesDo: [:key :value| ...]
>
>
> Joachim
>
>
>
> Am 23.01.24 um 17:24 schrieb sergio ruiz:
>
> I need to iterate over a dictionary.
>
> I asked the AI buddy for a little help, and he says:
>
> | myDictionary |
>
> "Create a dictionary"
> myDictionary := Dictionary new.
> myDictionary at: 'one' put: 1.
> myDictionary at: 'two' put: 2.
> myDictionary at: 'three' put: 3.
>
> "Iterate over the dictionary"
> myDictionary do: [ :key :value |
> Transcript show: key , ' -> ', value printString ; nl.
> ].
>
> but when i try this, I get:
>
> ArgumentsCountMismatch: This block accepts 2 arguments, but was called with 1 argument.
>
> Is the AI using a different dialect of smalltalk?
>
> how would I go about acting on each pair?
>
> Thanks!
>
> ----
> peace,
> sergio
> photographer, journalist, visionary
>
> Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2
> #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
> @sergio_101@mastodon.social
> https://sergio101.com
> http://www.codeandmusic.com
> http://www.twitter.com/sergio_101
> http://www.facebook.com/sergio101
>
> --
>
> -----------------------------------------------------------------------
> Objektfabrik Joachim Tuchel mailto:jtuchel@objektfabrik.de
> Fliederweg 1 http://www.objektfabrik.de
> D-71640 Ludwigsburg http://joachimtuchel.wordpress.com
> Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1
>
>