News for hackers. Stuff that matters.
Re:Crafting Code in Clojure by robertfw on Friday February 01, 2013 @06:01PM (#5154125)
Thanks for this post! I'm diving into clojure (currently a python dev), and I'm starting to get that tingly anticipation of being able to use these kinds of tools. It was really useful to see how you iterate through your solution.
Re:Crafting Code in Clojure by eckzow on Friday February 01, 2013 @10:14PM (#5154986)
That's funny--as a python guy I was squirming for a set comprehension immediately:

  >>> a = {'a':1,'b':2}
  >>> b = {'b':3,'c':4}
  >>> def keylist(*maps):
  ...     return ', '.join(sorted({str(k) for m in maps for k in m.keys()})) or '<none>'
  ...
  >>> keylist(a, b)
  'a, b, c'
  >>> keylist()
  '<none>'
I'm sure people will have differing opinions on the readability of a nested set comprehension, but from the bullets at the top of the article to one-liner implementation in ~30 seconds. (For an arbitrary number of maps, no less.)

(edit: added '<none>' on empty, fixed formatting, whoops now I'm over 30 seconds :))

Re:Crafting Code in Clojure by robertfw on Sunday February 03, 2013 @04:15AM (#5159172)
Someone pointed out elsewhere in the thread that this kind of code has to be read from the inside out, and for that reason I think the clojure code makes a better balance of readable vs succinct.
Re:Crafting Code in Clojure by ims on Saturday February 02, 2013 @11:36AM (#5156406)
This is pretty pedantic, but wouldn't

    for k in m
be more "pythonic" than

    for k in m.keys()

?