[Cuis-dev] creating a Dictionary

Jaromir Matas mail at jaromir.net
Sun Jul 7 14:46:23 PDT 2024




On 07-Jul-24 11:06:12 PM, "Mark Volkmann via Cuis-dev" 
<cuis-dev at lists.cuis.st> wrote:

>It seems that `Dictionary newFrom:` works with a run-time literal Array 
>of Association objects and does not work with a compile-time literal 
>Array or Association objects. For example, this works:
>
>as := {#a -> 'apple'. #b -> 'banana'. #c -> 'cherry'}.
>d2 := Dictionary newFrom: as.
>
>but this gives the error "MessageNotUnderstood: Symbol>>key".
>
>as := #(#a -> 'apple' #b -> 'banana' #c -> 'cherry').

as = #(#a #-> 'apple' #b #-> 'banana' #c #-> 'cherry')

i.e. `as` is not an array of associations :) Literal array won't create 
the association objects, or better to say the compiler doesn't do 
compile time evaluation. Check 
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Documentation/Technical/HitchHikersCompiler.md 
and scroll to `Compile Time Evaluation` section.


>
>d2 := Dictionary newFrom: as.
>
>Can someone explain why?
>
>--
>R. Mark Volkmann
>Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240707/34b823ed/attachment.htm>


More information about the Cuis-dev mailing list