On Thu, Jun 18, 2009 at 6:30 PM, Howard Lewis Ship <[email protected]> wrote:
> I have code that gets passed a map (actually a struct-map), should I
>
> (my-map :my-key)
> or
> (:my-key my-map)
>
> I'm beginning to gravitate towards the latter, as it is more tolerant of
> the map being nil.
>
I prefer the (map key) order. One reason is that it is consistent with a
cool use of sets that Stuart Halloway taught me. Here's an example:
(def vowel? (set "aeiou"))
(defn pig-latin [word]
(let [first-letter (first word)]
(if (vowel? first-letter)
(str word "ay")
(str (subs word 1) first-letter "ay"))))
(println (pig-latin "red"))
(println (pig-latin "orange"))
Note how vowel? isn't really a function. It's a set which is why def is used
to define vowel? instead of defn. When it is used, it seems more readable to
write (vowel? letter) than (letter vowel?).
--
R. Mark Volkmann
Object Computing, Inc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---