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.