Re: destructuring vectors with :or
Clojure documentation only talks about :or followed by a map (from http://clojure.org/special_forms ): Also optionally, an *:or* key in the binding form followed by another map may be used to supply default values for some or all of the keys if they are not found in the init-expr: (let [{a :a, b :b, c :c, :as m :or {a 2 b 3}} {:a 5 :c 6}] [a b c m]) -[5 3 6 {:c 6, :a 5}] On Friday, April 12, 2013 6:00:27 PM UTC-4, henry clifford wrote: I'm trying to use the :or destructuring syntax as seen here applied to a map (def point {:y 7}) (let [{:keys [x y] :or {x 0 y 0}} point] (println x: x y: y)) x: 0 y: 7 but I can't get this to work with vectors: (def point [7]) (let [[x y :or [0 0]] point] (println x: x y: y)) what' I'm expecting is x:7 y:0 but I'm getting Exception Unsupported binding form: :or Any thoughts on this? Thanks! -- -- 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/groups/opt_out.
Re: destructuring vectors with :or
Fantastic, thank you! On Friday, April 12, 2013 11:13:23 PM UTC+1, John Hume wrote: You can use a map destructuring form on a vector like so: (let [{x 0 y 1 :or {x 0 y 0}} [7]] [x y]) returns [7 0] On Fri, Apr 12, 2013 at 5:00 PM, henry clifford h.a.cl...@gmail.comjavascript: wrote: I'm trying to use the :or destructuring syntax as seen here applied to a map (def point {:y 7}) (let [{:keys [x y] :or {x 0 y 0}} point] (println x: x y: y)) x: 0 y: 7 but I can't get this to work with vectors: (def point [7]) (let [[x y :or [0 0]] point] (println x: x y: y)) what' I'm expecting is x:7 y:0 but I'm getting Exception Unsupported binding form: :or Any thoughts on this? Thanks! -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- http://elhumidor.blogspot.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 --- 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/groups/opt_out.
destructuring vectors with :or
I'm trying to use the :or destructuring syntax as seen here applied to a map (def point {:y 7}) (let [{:keys [x y] :or {x 0 y 0}} point] (println x: x y: y)) x: 0 y: 7 but I can't get this to work with vectors: (def point [7]) (let [[x y :or [0 0]] point] (println x: x y: y)) what' I'm expecting is x:7 y:0 but I'm getting Exception Unsupported binding form: :or Any thoughts on this? Thanks! -- -- 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/groups/opt_out.
Re: destructuring vectors with :or
You can use a map destructuring form on a vector like so: (let [{x 0 y 1 :or {x 0 y 0}} [7]] [x y]) returns [7 0] On Fri, Apr 12, 2013 at 5:00 PM, henry clifford h.a.cliff...@gmail.com wrote: I'm trying to use the :or destructuring syntax as seen here applied to a map (def point {:y 7}) (let [{:keys [x y] :or {x 0 y 0}} point] (println x: x y: y)) x: 0 y: 7 but I can't get this to work with vectors: (def point [7]) (let [[x y :or [0 0]] point] (println x: x y: y)) what' I'm expecting is x:7 y:0 but I'm getting Exception Unsupported binding form: :or Any thoughts on this? Thanks! -- -- 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/groups/opt_out. -- http://elhumidor.blogspot.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 --- 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/groups/opt_out.