help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Dictionary usage question..


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Dictionary usage question..
Date: Thu, 27 Sep 2012 08:44:16 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1

Il 27/09/2012 03:39, Rick Flower ha scritto:
> Ok.. I changed the way the dictionary was created and
> it's now being done as follows to eliminate the association,
> just to simplify.  If it matters I'm using version 3.2 of GST..
> 
> dictionaryForAttributes: aCollection [
>     | dict |
>     dict := Dictionary new.
>     aCollection do: [:each | dict at: each key put: each value ].
>     ^dict.
> "    ^Dictionary withAll: (aCollection
>         collect: [ :each | each key type -> each value ])"
> ]
> 
> Here's the code that populates it from an array of XML.Attributes:
>     attributes := self dictionaryForAttributes: (each attributes).
> 
> Here's the results of what's now in the attributes dictionary :
>     attributes inspect.
> 
> An instance of Dictionary
>   tally: 2
>   contents: [
>     {link}->'http://foobar.com'
>     {label}->'use-case-Name-1'
>   ]

The braces are the important part here.  These are not string, they are
NodeTag objects (it is documented: try "XML.Attribute comment").  Thus
you need:

aCollection do: [:each | dict at: each name asString put: each value ].

to build the dictionary.

Paolo

> Here's the code that is trying to do a lookup for an item in the
> dictionary..
> 
>     labelName := attributes at: 'label'.
> 
> And here's the results..
> 
> Object: Dictionary new: 32 "<-0x53bb440>" error: Invalid argument label:
> key not found
> SystemExceptions.NotFound(Exception)>>signal (ExcHandling.st:254)
> SystemExceptions.NotFound(Exception)>>signal: (ExcHandling.st:264)
> SystemExceptions.NotFound class>>signalOn:what: (SysExcept.st:758)
> [] in Dictionary>>at: (Dictionary.st:139)
> Dictionary>>at:ifAbsent: (Dictionary.st:149)
> Dictionary>>at: (Dictionary.st:138)
> 
> I just don't get it.. I must be missing something here..





reply via email to

[Prev in Thread] Current Thread [Next in Thread]