On 20 October 2012 10:49, Frank Shearar <frank.shearar@gmail.com> wrote:
Ruby: {:foo => 1, :bar => 2} Clojure: {:foo 1 :bar 2} Python: {'foo': 1, 'bar': 2}
That's it? I can add some more :) This is interesting actually.. how hard you must try in attempt to make it look sane and readable. Dicts is quite complex data structure for describing in text. Another thing is , how often you need something more complex than dictionary where keys and values is both simple values? (i am talking about literals , of course). Dictionaries as keys? Just out of practical reasons #hash and #= is quite expensive to calculate for dictionary, for using them as keys. In my practice, using dictionary as key/values in another dictionary (or any other object) having sense only when you use identity dictionary (to serve as cache) but not within regular dictionary. And again, cache is usually constructed dynamically, not from literal(s). Also, how often you need more than two levels of nesting for describing literal data structure? Because, even if you will have nice syntax to denote dicts vs arrays vs lists, if you start nesting them deeply, at some point you will find that it is no longer readable, because you will get lost in [{() }]} maze very soon. And for shallow hierarchies, distinct syntax is not really important.
frank
I do not see a need in having separate syntax for dictionary. Because this goes to nowhere in form of never-ending story: - tomorrow i want syntactic sugar for Sets
Because with syntax for lists and dictionaries you can roll any kind of literal you might care for.
- then for Colors
A dictionary with keys of 'r', 'g' and 'b', Or 'c', 'm', 'y', 'k'. Or anything else.
how you determine that this is Color but not dictionary which coincidentally has same keys?
- then for Points, Rectangles and Circles
A dictionary with 'x' and 'y' keys (or 'rho' and 'theta'), a list of four dictionaries (for the points), and a list with two dictionaries for the points.
same again, list with 'x' and 'y' is not Point list with 4 dictionaries is not Rectangle etc.
... - and Pink Elephants
one of the reasons, why i like smalltalk syntax, is small grammar, minimal syntactic constructs, yet high expressive power. Smalltalk (and LISP) is a good demonstration that massive set of different syntax sugars/rules and expressive power are not correlating values.
Ah, but it's precisely Lisp's uniformity in appearance that trips people up. And that's precisely why in Clojure a list is (1 2 3), a vector is [1 2 3] and a dictionary is {:a 1 :b 2} - different things are visually distinct.
You don't need a _lot_ of difference, because a little goes a long way.
frank
-- Best regards, Igor Stasenko.