Re: Question about doseq
Hi, Am Mittwoch, 31. Oktober 2012 01:29:11 UTC+1 schrieb Ryan T.: user= (doseq [[id item] my-hash key (:a-key item)] (println key)) [:value a value] [:value a value] nil The next step in the doseq also introduces a seq traversal. So your map is turned into a sequence of map entries. You can see this by providing map with more than one entry. To get your result try the following (combined with prn mentioned already): (doseq [[id item] my-hash :let [key (:a-key item)]] (prn key)) Kind regards Meikel -- 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
Re: Question about doseq
Thank you both for your replies, they were very helpful. Regards, Ryan On Wednesday, October 31, 2012 2:29:11 AM UTC+2, Ryan T. wrote: Hello all, I have the following code: (def my-hash {1 {:a-key {:value a value} :another-key another value :a-third-key []} 2 {:a-key {:value a value} :another-key another value :a-third-key []}} In the following example i get the following result: user= (doseq [[id item] my-hash] (println item)) {:a-key {:value a value}, :another-key another value, :a-third-key []} {:a-key {:value a value}, :another-key another value, :a-third-key []} nil On the above example, it looks *almost* normal to me. For instance, why *{:value a value}* is not returned as *{:value a value} *? Same goes for *:another key* It still looks like a hashmap though. Isn't it? The behavior however which confused me even more is the following: user= (doseq [[id item] my-hash key (:a-key item)] (println key)) [:value a value] [:value a value] nil I was expecting the above to return: {:value a value} {:value a value} nil Can someone explain to me why vector is being returned and how can I achieve the result I was expecting? What am I missing here? Am i misusing the doseq http://clojuredocs.org/clojure_core/clojure.core/doseqbindings? Thank you for your time -- 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
Re: Question about doseq
*Meikel*, I do have one more question. I posted another question some time ago and the answer I got was thishttps://groups.google.com/d/msg/clojure/79AXDY4Gp7w/As9LZYDT87AJ. I am a little bit confused why *:let *is not required there but I had to use it to make it work in this case. Regards, Ryan On Wednesday, October 31, 2012 8:27:13 AM UTC+2, Meikel Brandmeyer (kotarak) wrote: Hi, Am Mittwoch, 31. Oktober 2012 01:29:11 UTC+1 schrieb Ryan T.: user= (doseq [[id item] my-hash key (:a-key item)] (println key)) [:value a value] [:value a value] nil The next step in the doseq also introduces a seq traversal. So your map is turned into a sequence of map entries. You can see this by providing map with more than one entry. To get your result try the following (combined with prn mentioned already): (doseq [[id item] my-hash :let [key (:a-key item)]] (prn key)) Kind regards Meikel -- 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
Re: Question about doseq
Hi, I'm not sure what you are refering to in the provided link. If it's eg. about :warehouses, then the difference is, that :warehouses contains a vector in the example in the link. So you basically walk the warehouse vector one warehouse at a time. But here you of only a single item (the map), so you have to use :let. In case you'd want to treat the :warehouses vector also as single item (instead of walking it), you'd also have to add a :let there. Bottom line: :let keeps item as single entity, no-:let walks item as sequence in an inner loop. (for [x [[1 2] [3 4] [5 6]] y x] y) = (1 2 3 4 5 6) (for [x [[1 2] [3 4] [5 6]] :let [y x]] y) = ([1 2] [3 4] [5 6]) I used for here, but doseq works the same way. Hope this clarifies. Meikel -- 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
Re: Question about doseq
Thanks Meikel, your answer was very clear. On Wednesday, October 31, 2012 12:49:06 PM UTC+2, Meikel Brandmeyer (kotarak) wrote: Hi, I'm not sure what you are refering to in the provided link. If it's eg. about :warehouses, then the difference is, that :warehouses contains a vector in the example in the link. So you basically walk the warehouse vector one warehouse at a time. But here you of only a single item (the map), so you have to use :let. In case you'd want to treat the :warehouses vector also as single item (instead of walking it), you'd also have to add a :let there. Bottom line: :let keeps item as single entity, no-:let walks item as sequence in an inner loop. (for [x [[1 2] [3 4] [5 6]] y x] y) = (1 2 3 4 5 6) (for [x [[1 2] [3 4] [5 6]] :let [y x]] y) = ([1 2] [3 4] [5 6]) I used for here, but doseq works the same way. Hope this clarifies. Meikel -- 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
Question about doseq
Hello all, I have the following code: (def my-hash {1 {:a-key {:value a value} :another-key another value :a-third-key []} 2 {:a-key {:value a value} :another-key another value :a-third-key []}} In the following example i get the following result: user= (doseq [[id item] my-hash] (println item)) {:a-key {:value a value}, :another-key another value, :a-third-key []} {:a-key {:value a value}, :another-key another value, :a-third-key []} nil On the above example, it looks *almost* normal to me. For instance, why *{:value a value}* is not returned as *{:value a value} *? Same goes for *:another key* It still looks like a hashmap though. Isn't it? The behavior however which confused me even more is the following: user= (doseq [[id item] my-hash key (:a-key item)] (println key)) [:value a value] [:value a value] nil I was expecting the above to return: {:value a value} {:value a value} nil Can someone explain to me why vector is being returned and how can I achieve the result I was expecting? What am I missing here? Am i misusing the doseq http://clojuredocs.org/clojure_core/clojure.core/doseqbindings? Thank you for your time -- 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
Re: Question about doseq
Please use prn insteadof println. By default, pr and prn print in a way that objects can be read by the reader,but print and println produce output for human consumption. 2012/10/31 arekanderu arekand...@gmail.com Hello all, I have the following code: (def my-hash {1 {:a-key {:value a value} :another-key another value :a-third-key []} 2 {:a-key {:value a value} :another-key another value :a-third-key []}} In the following example i get the following result: user= (doseq [[id item] my-hash] (println item)) {:a-key {:value a value}, :another-key another value, :a-third-key []} {:a-key {:value a value}, :another-key another value, :a-third-key []} nil On the above example, it looks *almost* normal to me. For instance, why *{:value a value}* is not returned as *{:value a value} *? Same goes for *:another key* It still looks like a hashmap though. Isn't it? The behavior however which confused me even more is the following: user= (doseq [[id item] my-hash key (:a-key item)] (println key)) [:value a value] [:value a value] nil I was expecting the above to return: {:value a value} {:value a value} nil Can someone explain to me why vector is being returned and how can I achieve the result I was expecting? What am I missing here? Am i misusing the doseq http://clojuredocs.org/clojure_core/clojure.core/doseqbindings? Thank you for your time -- 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 -- 庄晓丹 Email:killme2...@gmail.com xzhu...@avos.com Site: http://fnil.net Twitter: @killme2008 -- 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