Re: (merge) = nil
I sort of remember Rich Hickey say this, but I am not sure :). I was a bit mistaken. In this video ( http://blip.tv/clojure/clojure-data-structures-part-2-714064 ) , around 42nd minute, he says that assoc is the normal way and is more convenient because you can assoc multiple keys and values without having to create a map out of them: (assoc m :a 1 :b 2) ; vs. (conj m {:a 1 :b 2}) On Thursday, August 30, 2012 1:31:41 AM UTC+2, dmirylenka wrote: I sort of remember Rich Hickey say this, but I am not sure :). As far as I see it, it is generally better to use more specific functions, as they make the assumptions about the types of the arguments more explicit. Sometimes they are also more efficient (but probably not in this case). So, for working with maps assoc is more preferable, as it is specific to maps (at least for non-integer keys). Polymorphic functions are nice when the concrete argument type is not important (e.g. list vs. vector). But in practice very few code is not going care whether it's working with map or a sequence - so conj is kind of overly polymorphic. This extra polymorphism can be confusing, for instance, if one tries to figure out the type of the following expression: (conj something [1 2]). contains? is maybe another example of generic function that has created confusion. That's my understanding ) . On Thursday, August 30, 2012 12:05:48 AM UTC+2, Meikel Brandmeyer (kotarak) wrote: Hi, Am 29.08.2012 um 23:38 schrieb dmirylenka: Although, code working with maps shouldn't use conj anyway. Why? 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
(merge) = nil
Why does `(merge)` return nil? I would have expected it to return the unit ({}) by analogy with things like this: (+) = 0 (*) = 1 - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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: (merge) = nil
Don't know why nil is returned instead of {}, but (+) = 0 (*) = 1 following that line of reasoning: (merge nil {:a 1}) {:a 1} (merge {} {:a 1}) {:a 1} -- 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: (merge) = nil
My guess is that `merge` has an invariant if all args are nil, return nil, making calls to `seq` contagious from args to return value. = (merge (seq {}) (seq {})) nil Just a guess though. Thanks, Ambrose On Thu, Aug 30, 2012 at 12:18 AM, Brian Marick mar...@exampler.com wrote: Why does `(merge)` return nil? I would have expected it to return the unit ({}) by analogy with things like this: (+) = 0 (*) = 1 - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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 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: (merge) = nil
An empty sequence is equal to nil. 2012/8/29 Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com: My guess is that `merge` has an invariant if all args are nil, return nil, making calls to `seq` contagious from args to return value. = (merge (seq {}) (seq {})) nil Just a guess though. Thanks, Ambrose On Thu, Aug 30, 2012 at 12:18 AM, Brian Marick mar...@exampler.com wrote: Why does `(merge)` return nil? I would have expected it to return the unit ({}) by analogy with things like this: (+) = 0 (*) = 1 - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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 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 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: (merge) = nil
On Thu, Aug 30, 2012 at 12:41 AM, Joop Kiefte iko...@gmail.com wrote: An empty sequence is equal to nil. What do you mean? = (seq? ()) true = (= nil ()) false 2012/8/29 Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com: My guess is that `merge` has an invariant if all args are nil, return nil, making calls to `seq` contagious from args to return value. = (merge (seq {}) (seq {})) nil Just a guess though. Thanks, Ambrose On Thu, Aug 30, 2012 at 12:18 AM, Brian Marick mar...@exampler.com wrote: Why does `(merge)` return nil? I would have expected it to return the unit ({}) by analogy with things like this: (+) = 0 (*) = 1 - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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 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 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 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: (merge) = nil
This isn't true in Clojure: http://clojure.org/lisps However, most functions treat an empty seq as nil because they call `seq' on their arguments. On Wed, Aug 29, 2012 at 6:41 PM, Joop Kiefte iko...@gmail.com wrote: An empty sequence is equal to nil. 2012/8/29 Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com: My guess is that `merge` has an invariant if all args are nil, return nil, making calls to `seq` contagious from args to return value. = (merge (seq {}) (seq {})) nil Just a guess though. Thanks, Ambrose On Thu, Aug 30, 2012 at 12:18 AM, Brian Marick mar...@exampler.com wrote: Why does `(merge)` return nil? I would have expected it to return the unit ({}) by analogy with things like this: (+) = 0 (*) = 1 - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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 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 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 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: (merge) = nil
On Wed, Aug 29, 2012 at 9:41 AM, Joop Kiefte iko...@gmail.com wrote: An empty sequence is equal to nil. How so? user (some #(= % nil) ['() [] {}]) nil -- Ben Wolfson Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure. [Larousse, Drink entry] -- 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: (merge) = nil
I would say, they treat nil as an empty sequence, which makes nil, effectively, a unit: (assoc nil :a :b) ; = {:a :b} (merge nil {:a :b}) ; = {:a :b} etc. On Wednesday, August 29, 2012 7:36:26 PM UTC+2, Moritz Ulrich wrote: This isn't true in Clojure: http://clojure.org/lisps However, most functions treat an empty seq as nil because they call `seq' on their arguments. On Wed, Aug 29, 2012 at 6:41 PM, Joop Kiefte iko...@gmail.comjavascript: wrote: An empty sequence is equal to nil. 2012/8/29 Ambrose Bonnaire-Sergeant abonnair...@gmail.com javascript: : My guess is that `merge` has an invariant if all args are nil, return nil, making calls to `seq` contagious from args to return value. = (merge (seq {}) (seq {})) nil Just a guess though. Thanks, Ambrose On Thu, Aug 30, 2012 at 12:18 AM, Brian Marick mar...@exampler.comjavascript: wrote: Why does `(merge)` return nil? I would have expected it to return the unit ({}) by analogy with things like this: (+) = 0 (*) = 1 - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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 post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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 post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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 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: (merge) = nil
On Aug 29, 2012, at 12:18 PM, Brian Marick mar...@exampler.com wrote: Why does `(merge)` return nil? I would have expected it to return the unit ({}) I agree with your intuition -- I expected an empty map. However, the doc says Returns a map that consists of the rest of the maps conj-ed onto the first which implies that correct usage needs at least one map. As an aside, it doesn't say anything about nil arguments, but they seem to be supported as well as maps. My guess, based on a quick look at some of the commits, is that allowing nil as an argument was convenient for some metadata manipulations, and the edge case of no-arguments wasn't considered important. It looks like it would be easy to fix and probably wouldn't break any code since no one should be depending on the undocumented nullary behavior. Steve Miner stevemi...@gmail.com -- 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: (merge) = nil
Hm.. There seem to be cases when nil is not equivalent to {} when working with maps: (conj {} [:a :b]); = {:a :b} (conj nil [:a :b]); = ([:a :b]) Although, code working with maps shouldn't use conj anyway. Any other examples? On Wednesday, August 29, 2012 9:08:07 PM UTC+2, dmirylenka wrote: I would say, they treat nil as an empty sequence, which makes nil, effectively, a unit: (assoc nil :a :b) ; = {:a :b} (merge nil {:a :b}) ; = {:a :b} etc. On Wednesday, August 29, 2012 7:36:26 PM UTC+2, Moritz Ulrich wrote: This isn't true in Clojure: http://clojure.org/lisps However, most functions treat an empty seq as nil because they call `seq' on their arguments. On Wed, Aug 29, 2012 at 6:41 PM, Joop Kiefte iko...@gmail.com wrote: An empty sequence is equal to nil. 2012/8/29 Ambrose Bonnaire-Sergeant abonnair...@gmail.com: My guess is that `merge` has an invariant if all args are nil, return nil, making calls to `seq` contagious from args to return value. = (merge (seq {}) (seq {})) nil Just a guess though. Thanks, Ambrose On Thu, Aug 30, 2012 at 12:18 AM, Brian Marick mar...@exampler.com wrote: Why does `(merge)` return nil? I would have expected it to return the unit ({}) by analogy with things like this: (+) = 0 (*) = 1 - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@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 post to this group, send email to clo...@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+u...@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 post to this group, send email to clo...@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+u...@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 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: (merge) = nil
Hi, Am 29.08.2012 um 23:38 schrieb dmirylenka: Although, code working with maps shouldn't use conj anyway. Why? Kind regards Meikel signature.asc Description: Message signed with OpenPGP using GPGMail
Re: (merge) = nil
On Aug 29, 2012, at 2:08 PM, dmirylenka wrote: I would say, they treat nil as an empty sequence, which makes nil, effectively, a unit: (assoc nil :a :b) ; = {:a :b} (merge nil {:a :b}) ; = {:a :b} It's not a unit if you're using `if-let` and expect nil to represent failure and {} to represent a success that establishes no bindings. - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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: (merge) = nil
I sort of remember Rich Hickey say this, but I am not sure :). As far as I see it, it is generally better to use more specific functions, as they make the assumptions about the types of the arguments more explicit. Sometimes they are also more efficient (but probably not in this case). So, for working with maps assoc is more preferable, as it is specific to maps (at least for non-integer keys). Polymorphic functions are nice when the concrete argument type is not important (e.g. list vs. vector). But in practice very few code is not going care whether it's working with map or a sequence - so conj is kind of overly polymorphic. This extra polymorphism can be confusing, for instance, if one tries to figure out the type of the following expression: (conj something [1 2]). contains? is maybe another example of generic function that has created confusion. That's my understanding ) . On Thursday, August 30, 2012 12:05:48 AM UTC+2, Meikel Brandmeyer (kotarak) wrote: Hi, Am 29.08.2012 um 23:38 schrieb dmirylenka: Although, code working with maps shouldn't use conj anyway. Why? 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: (merge) = nil
It's not a unit if you're using `if-let` and expect nil to represent failure and {} to represent a success that establishes no bindings. You mean, something like this, right? : (if-let [{:keys [a]} {}] Hi); = Hi (if-let [{:keys [a]} nil] Hi); = nil Interesting example! In my own code, however, I wouldn't use a collection (in this case, a map) as a test expression inside if (which happens here under the hood). Exactly because in many cases empty sequence is equivalent to nil. Instead, I would explicitly test for emptiness: (if (seq my-map) this that). On Thursday, August 30, 2012 12:46:05 AM UTC+2, Brian Marick wrote: On Aug 29, 2012, at 2:08 PM, dmirylenka wrote: I would say, they treat nil as an empty sequence, which makes nil, effectively, a unit: (assoc nil :a :b) ; = {:a :b} (merge nil {:a :b}) ; = {:a :b} It's not a unit if you're using `if-let` and expect nil to represent failure and {} to represent a success that establishes no bindings. - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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