Re: Supplied-p parameter in clojure similar to lisp lambda lists
I created a ticket http://dev.clojure.org/jira/browse/CLJ-1508 2014-08-18 11:02 GMT+08:00 dennis zhuang killme2...@gmail.com: I think that adding a :p option to destructuring would be great: (let [ {:keys [a b c] :p {a a-p}} params] (if a-p (println a) (println a is not exists.))) 2014-08-17 20:05 GMT+08:00 Dave Tenny dave.te...@gmail.com: Well, it took me a while to perhaps get what you were telling me here. In my case I I had something like (defn foo [ {:keys [bar ... more keys ...] :or {bar 1}} ] ...) and I wanted to know whether the user had explicilty invoked foo with :bar. What wasn't clear to me was that :as solved this problem. Reading http://clojure.org/special_forms#Special Forms--Binding Forms (Destructuring)-Map binding destructuring I guess I can see that it's telling me :as shows things that weren't in the init-form, but that's with hindsight. So, to emulated common lisp 'supplied-p' semantics, you can check the :as form, which will **not** contain :or values for keywords. E.g. user (defn bar [ {:keys [baz] :or {baz 'baz} :as all-keys} ] (println baz all-keys)) #'user/bar user (bar :bof 1) baz {:bof 1} nil And not that the all-keys form does not show a binding for baz, and that's what I wanted. Just fyi in case anybody searches topics for 'supplied-p' again. On Saturday, June 21, 2014 7:22:13 PM UTC-4, Jason Felice wrote: If you destructure the parameters like this: (defn f [ {:as a-map}] ...) You can use map primitives on a-map. But you can also supply defaults here. On Jun 20, 2014 2:14 PM, Dave Tenny dave@gmail.com wrote: What is the commonly accepted technique for declaring/using 'supplied-p' type lambda list functionality in clojure? http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/ HyperSpec/Body/sec_3-4-1.html I have some clojure functions with a large number of keywords and various defaults, I want to know if a keyword was specified by the caller (rather than defaulted) in some cases. Certainly I could implement my own destructuring macros that did this, but I'd like to avoid reinventing a wheel here if I can, and also to know the idiomatic clojure way to do it. Thanks for any tips. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- 庄晓丹 Email:killme2...@gmail.com xzhu...@avos.com Site: http://fnil.net Twitter: @killme2008 -- 庄晓丹 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 --- 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.
Re: Supplied-p parameter in clojure similar to lisp lambda lists
I don't think that a :p feature is necessary, since all you need to do to emulate it is a (:baz all-keys) to know if the user explicitly specified it. I.e. I think the capability is already present in adequate form but the documentation on map destructuring could be improved. On Sun, Aug 17, 2014 at 11:02 PM, dennis zhuang killme2...@gmail.com wrote: I think that adding a :p option to destructuring would be great: (let [ {:keys [a b c] :p {a a-p}} params] (if a-p (println a) (println a is not exists.))) 2014-08-17 20:05 GMT+08:00 Dave Tenny dave.te...@gmail.com: Well, it took me a while to perhaps get what you were telling me here. In my case I I had something like (defn foo [ {:keys [bar ... more keys ...] :or {bar 1}} ] ...) and I wanted to know whether the user had explicilty invoked foo with :bar. What wasn't clear to me was that :as solved this problem. Reading http://clojure.org/special_forms#Special Forms--Binding Forms (Destructuring)-Map binding destructuring I guess I can see that it's telling me :as shows things that weren't in the init-form, but that's with hindsight. So, to emulated common lisp 'supplied-p' semantics, you can check the :as form, which will **not** contain :or values for keywords. E.g. user (defn bar [ {:keys [baz] :or {baz 'baz} :as all-keys} ] (println baz all-keys)) #'user/bar user (bar :bof 1) baz {:bof 1} nil And not that the all-keys form does not show a binding for baz, and that's what I wanted. Just fyi in case anybody searches topics for 'supplied-p' again. On Saturday, June 21, 2014 7:22:13 PM UTC-4, Jason Felice wrote: If you destructure the parameters like this: (defn f [ {:as a-map}] ...) You can use map primitives on a-map. But you can also supply defaults here. On Jun 20, 2014 2:14 PM, Dave Tenny dave@gmail.com wrote: What is the commonly accepted technique for declaring/using 'supplied-p' type lambda list functionality in clojure? http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/ HyperSpec/Body/sec_3-4-1.html I have some clojure functions with a large number of keywords and various defaults, I want to know if a keyword was specified by the caller (rather than defaulted) in some cases. Certainly I could implement my own destructuring macros that did this, but I'd like to avoid reinventing a wheel here if I can, and also to know the idiomatic clojure way to do it. Thanks for any tips. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- 庄晓丹 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 --- You received this message because you are subscribed to a topic in the Google Groups Clojure group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/jWc51JOkvsA/unsubscribe. To unsubscribe from this group and all its topics, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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
Re: Supplied-p parameter in clojure similar to lisp lambda lists
Yep, it's an optional syntax sugar. Indeed, you should use (contains? all-keys :baz) to check if :baz is present in options. If :baz is present but it's value is nil,then (:baz all-keys) returns nil too. 2014-08-18 18:57 GMT+08:00 Dave Tenny dave.te...@gmail.com: I don't think that a :p feature is necessary, since all you need to do to emulate it is a (:baz all-keys) to know if the user explicitly specified it. I.e. I think the capability is already present in adequate form but the documentation on map destructuring could be improved. On Sun, Aug 17, 2014 at 11:02 PM, dennis zhuang killme2...@gmail.com wrote: I think that adding a :p option to destructuring would be great: (let [ {:keys [a b c] :p {a a-p}} params] (if a-p (println a) (println a is not exists.))) 2014-08-17 20:05 GMT+08:00 Dave Tenny dave.te...@gmail.com: Well, it took me a while to perhaps get what you were telling me here. In my case I I had something like (defn foo [ {:keys [bar ... more keys ...] :or {bar 1}} ] ...) and I wanted to know whether the user had explicilty invoked foo with :bar. What wasn't clear to me was that :as solved this problem. Reading http://clojure.org/special_forms#Special Forms--Binding Forms (Destructuring)-Map binding destructuring I guess I can see that it's telling me :as shows things that weren't in the init-form, but that's with hindsight. So, to emulated common lisp 'supplied-p' semantics, you can check the :as form, which will **not** contain :or values for keywords. E.g. user (defn bar [ {:keys [baz] :or {baz 'baz} :as all-keys} ] (println baz all-keys)) #'user/bar user (bar :bof 1) baz {:bof 1} nil And not that the all-keys form does not show a binding for baz, and that's what I wanted. Just fyi in case anybody searches topics for 'supplied-p' again. On Saturday, June 21, 2014 7:22:13 PM UTC-4, Jason Felice wrote: If you destructure the parameters like this: (defn f [ {:as a-map}] ...) You can use map primitives on a-map. But you can also supply defaults here. On Jun 20, 2014 2:14 PM, Dave Tenny dave@gmail.com wrote: What is the commonly accepted technique for declaring/using 'supplied-p' type lambda list functionality in clojure? http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/ HyperSpec/Body/sec_3-4-1.html I have some clojure functions with a large number of keywords and various defaults, I want to know if a keyword was specified by the caller (rather than defaulted) in some cases. Certainly I could implement my own destructuring macros that did this, but I'd like to avoid reinventing a wheel here if I can, and also to know the idiomatic clojure way to do it. Thanks for any tips. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- 庄晓丹 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 --- You received this message because you are subscribed to a topic in the Google Groups Clojure group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/jWc51JOkvsA/unsubscribe. To unsubscribe from this group and all its topics, send an email to
Re: Supplied-p parameter in clojure similar to lisp lambda lists
Well, it took me a while to perhaps get what you were telling me here. In my case I I had something like (defn foo [ {:keys [bar ... more keys ...] :or {bar 1}} ] ...) and I wanted to know whether the user had explicilty invoked foo with :bar. What wasn't clear to me was that :as solved this problem. Reading http://clojure.org/special_forms#Special Forms--Binding Forms (Destructuring)-Map binding destructuring I guess I can see that it's telling me :as shows things that weren't in the init-form, but that's with hindsight. So, to emulated common lisp 'supplied-p' semantics, you can check the :as form, which will **not** contain :or values for keywords. E.g. user (defn bar [ {:keys [baz] :or {baz 'baz} :as all-keys} ] (println baz all-keys)) #'user/bar user (bar :bof 1) baz {:bof 1} nil And not that the all-keys form does not show a binding for baz, and that's what I wanted. Just fyi in case anybody searches topics for 'supplied-p' again. On Saturday, June 21, 2014 7:22:13 PM UTC-4, Jason Felice wrote: If you destructure the parameters like this: (defn f [ {:as a-map}] ...) You can use map primitives on a-map. But you can also supply defaults here. On Jun 20, 2014 2:14 PM, Dave Tenny dave@gmail.com javascript: wrote: What is the commonly accepted technique for declaring/using 'supplied-p' type lambda list functionality in clojure? http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/sec_3-4-1.html I have some clojure functions with a large number of keywords and various defaults, I want to know if a keyword was specified by the caller (rather than defaulted) in some cases. Certainly I could implement my own destructuring macros that did this, but I'd like to avoid reinventing a wheel here if I can, and also to know the idiomatic clojure way to do it. Thanks for any tips. -- 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 javascript: 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/d/optout. -- 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.
Re: Supplied-p parameter in clojure similar to lisp lambda lists
I think that adding a :p option to destructuring would be great: (let [ {:keys [a b c] :p {a a-p}} params] (if a-p (println a) (println a is not exists.))) 2014-08-17 20:05 GMT+08:00 Dave Tenny dave.te...@gmail.com: Well, it took me a while to perhaps get what you were telling me here. In my case I I had something like (defn foo [ {:keys [bar ... more keys ...] :or {bar 1}} ] ...) and I wanted to know whether the user had explicilty invoked foo with :bar. What wasn't clear to me was that :as solved this problem. Reading http://clojure.org/special_forms#Special Forms--Binding Forms (Destructuring)-Map binding destructuring I guess I can see that it's telling me :as shows things that weren't in the init-form, but that's with hindsight. So, to emulated common lisp 'supplied-p' semantics, you can check the :as form, which will **not** contain :or values for keywords. E.g. user (defn bar [ {:keys [baz] :or {baz 'baz} :as all-keys} ] (println baz all-keys)) #'user/bar user (bar :bof 1) baz {:bof 1} nil And not that the all-keys form does not show a binding for baz, and that's what I wanted. Just fyi in case anybody searches topics for 'supplied-p' again. On Saturday, June 21, 2014 7:22:13 PM UTC-4, Jason Felice wrote: If you destructure the parameters like this: (defn f [ {:as a-map}] ...) You can use map primitives on a-map. But you can also supply defaults here. On Jun 20, 2014 2:14 PM, Dave Tenny dave@gmail.com wrote: What is the commonly accepted technique for declaring/using 'supplied-p' type lambda list functionality in clojure? http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/ HyperSpec/Body/sec_3-4-1.html I have some clojure functions with a large number of keywords and various defaults, I want to know if a keyword was specified by the caller (rather than defaulted) in some cases. Certainly I could implement my own destructuring macros that did this, but I'd like to avoid reinventing a wheel here if I can, and also to know the idiomatic clojure way to do it. Thanks for any tips. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- 庄晓丹 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 --- 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.
Re: Supplied-p parameter in clojure similar to lisp lambda lists
If you destructure the parameters like this: (defn f [ {:as a-map}] ...) You can use map primitives on a-map. But you can also supply defaults here. On Jun 20, 2014 2:14 PM, Dave Tenny dave.te...@gmail.com wrote: What is the commonly accepted technique for declaring/using 'supplied-p' type lambda list functionality in clojure? http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/sec_3-4-1.html I have some clojure functions with a large number of keywords and various defaults, I want to know if a keyword was specified by the caller (rather than defaulted) in some cases. Certainly I could implement my own destructuring macros that did this, but I'd like to avoid reinventing a wheel here if I can, and also to know the idiomatic clojure way to do it. Thanks for any tips. -- 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. -- 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.
Supplied-p parameter in clojure similar to lisp lambda lists
What is the commonly accepted technique for declaring/using 'supplied-p' type lambda list functionality in clojure? http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/sec_3-4-1.html I have some clojure functions with a large number of keywords and various defaults, I want to know if a keyword was specified by the caller (rather than defaulted) in some cases. Certainly I could implement my own destructuring macros that did this, but I'd like to avoid reinventing a wheel here if I can, and also to know the idiomatic clojure way to do it. Thanks for any tips. -- 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.