Re: Is there an easier way to code this? Destructuring?

2010-07-30 Thread Daniel Glauser
Hi Joe, Laurent and Nikita, Thanks for your help, the destructuring form of [[k v]] is much cleaner, that's exactly what I was looking for. Nikita, thanks for catching the typo and the misplaced paren, the code is working smoothly now. I have problem coded in Java, I plan to complete the Clojure

Is there an easier way to code this? Destructuring?

2010-07-29 Thread Daniel Glauser
Hello folks, I'm working on some sample code and I have a feeling that there is an easier/more succinct way to code this. Any help or RTFM with a link is appreciated. Given: (def cookbook {:Coffee {:coffee 3, :sugar 1, :cream 1}, :Decaf-Coffee{:decaf 3, :sugar 1,

Re: Is there an easier way to code this? Destructuring?

2010-07-29 Thread Nikita Beloglazov
Hi, Daniel Here's my variant https://gist.github.com/49c6ac95b7456a150df8 Note, that in cookbook :Caffe-Moca should contain :cocoa, not :coco And I your variant calculating drink cost works incorrectly. (* (cost (key map-entry) (val map-entry))) should be replaced by (* (cost (key map-entry))

Re: Is there an easier way to code this? Destructuring?

2010-07-29 Thread Laurent PETIT
Hi, not really simplifying (in the sense of removing code), but (tentatively ?) de-obfuscating: (defn print-menu [menu] (do (println Menu:) (doseq [[drink number] menu] (println (str number , (drink-name drink) , (reduce (fn [acc-cost [ingredient

Re: Is there an easier way to code this? Destructuring?

2010-07-29 Thread joegg
I agree with Laurent's idea that you should pull this out as a separate function, but I think the most direct answer to your question is that you can bind the map entries in a destructuring as if they were two-element vectors. (map (fn [[ingr quant]] (* (cost ingr) quant)) (cookbook drink)) Joe