According to a Pharoer, there is no literal like #{...} in Pharo. But there is in Amber!
-- Is this a dictionary literal? I found that this works:
If I PrintIt, I get 'white'. If I remove #asDictionary, I still get 'white'! You received this message because you are subscribed to the Google Groups "amber-lang" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
It creates `HashedCollection`, not `Dictionary`, but both are Dictionary-like (except `HashedCollection` can only use strings as keys and is implemented using plain JS object, so you can pass it to JS libraries where key-value object is assumed).
Yes, it is Amber-specific. Richard Eng wrote: > According to a Pharoer, there is no literal like *#{...}* in Pharo. > But there is in Amber! > > Is this a dictionary literal? I found that this works: > > || dict | > dict := #{'foo'->'brown'. 'bar'->'yellow'. > 'qix'->'white'. 'baz'->'red'. 'flub'->'green'} asDictionary. > dict at: 'qix'| > If I *PrintIt*, I get 'white'. If I remove #asDictionary, I still get > 'white'! > > -- > You received this message because you are subscribed to the Google > Groups "amber-lang" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to [hidden email] > <mailto:[hidden email]>. > For more option -- You received this message because you are subscribed to the Google Groups "amber-lang" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Herby Vojčík wrote: > It creates `HashedCollection`, not `Dictionary`, but both are > Dictionary-like (except `HashedCollection` can only use strings as > keys and is implemented using plain JS object, so you can pass it to > JS libraries where key-value object is assumed). > > Yes, it is Amber-specific. > > Richard Eng wrote: >> According to a Pharoer, there is no literal like *#{...}* in Pharo. >> But there is in Amber! >> >> Is this a dictionary literal? I found that this works: >> >> || dict | >> dict := #{'foo'->'brown'. 'bar'->'yellow'. >> 'qix'->'white'. 'baz'->'red'. 'flub'->'green'} asDictionary. >> dict at: 'qix'| >> If I *PrintIt*, I get 'white'. If I remove #asDictionary, I still get >> 'white'! BTW, 'Inspect it' on the literal itself would answer your question on what it is immediately ;-) -- You received this message because you are subscribed to the Google Groups "amber-lang" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Whoa! That's cool!
-- I think it's best to avoid these literals when discussing Smalltalk in general. Anything Amber-specific will only confuse a novice. So, instead of a literal, just do:
This way, you aren't limited to just string values or number values; you can mix and match! On Friday, 5 June 2015 11:49:57 UTC-4, Herby wrote:
You received this message because you are subscribed to the Google Groups "amber-lang" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Richard Eng wrote: > Whoa! That's cool! > > I think it's best to avoid these literals when discussing Smalltalk in > general. Anything Amber-specific will only confuse a novice. So, > instead of a literal, just do: I disagree. Smalltalk syntax is so minimal (even with {...} dynamic arrays), one more element does not hurt, and the resulting code is much more readable. Moreover, Smalltalk encourages explorative programming. You can't escape having #{'key'->value. ...} explained, or the novice just won't understand the code he explores. A note that #{...} is Amber-specific may be enough. -- You received this message because you are subscribed to the Google Groups "amber-lang" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Okay, I'll buy that.
-- Btw, this discussion was started because I've been using a dictionary to simulate a Case Statement. However, I've discovered that the major shortcoming of using a dictionary is that you can't include a "default" case. While you can have a default case at the point of selection...
it's inconvenient that the default case is not directly associated with the dictionary. Any thoughts? On Friday, 5 June 2015 12:41:19 UTC-4, Herby wrote:
You received this message because you are subscribed to the Google Groups "amber-lang" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Richard Eng wrote: > Okay, I'll buy that. > > Btw, this discussion was started because I've been using a dictionary > to simulate a Case Statement. However, I've discovered that the major > shortcoming of using a dictionary is that you can't include a > "default" case. While you can have a default case at the point of > selection... > > || > dict at:inputValue ifAbsent:["default action"]. There is even a pattern for this (general, not Smalltalk-specific), I just read about it some month ago, don't know where (maybe at martinfowler.com). The solution is: dict at: inputValue ifAbsent: [ dict at: '_default' ifAbsent: [ "real problem" ]] > it's inconvenient that the default case is not directly associated > with the dictionary. Any thoughts? -- You received this message because you are subscribed to the Google Groups "amber-lang" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Oooh, I like that! Thanks very much.
-- On Friday, 5 June 2015 13:58:59 UTC-4, Herby wrote:
You received this message because you are subscribed to the Google Groups "amber-lang" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |