I am reading Clojure Applied, which I am enjoying. One code snippet is puzzling for me, can someone please explain why the authors used: (and (pos? cnt) instead of just (pos? cnt) ? Or to go further, (pos? (item @inventory))
The best I could think is that there used to be a check for two things: 1) that the entry was present in the map AND 2) the value for the entry was positive. But maybe there is some idiomatic use of "and" that I don't know about. The inventory atom is a map whose key is a keyword like :milk and the value is a count representing how many are left. (defn in-stock? "check if an item is in stock" [item] (let [cnt (item @inventory)] (and (pos? cnt)))) Excerpt From: Ben Vandgrift, Alex Miller. “Clojure Applied P1.” iBooks. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.