On 20 October 2012 20:52, Igor Stasenko <siguctua@gmail.com> wrote:
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 :)
I'm sure. These are just the ones I knew off the top of my head. I was too lazy to look up ML, Haskell, etc. syntax.
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?
There's a difference? :) I mean that only half in jest: it's idiomatic Clojure to do just this (use dictionaries to store structured data with named parts), and that's how CLOS works too. The only difference between the dictionary and the object is that the object also has keys pointing to methods. Most of the time though the source and target of the literal both have the same behaviour so there's not much need for transporting the methods. And you'd need much more machinery (well beyond the scope of this bikeshed) to permit the safe sending of data+code - capabilities, sandboxing, ... frank
- 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.