Sean, Thank you. That saves me hours of mistakes.
On Wednesday, September 30, 2015 at 9:38:09 PM UTC-4, Sean Corfield wrote: > > Your example works for me as follows: > > user> (defn- discern > > > ([this-users-conversation] > {:pre [(map? this-users-conversation)]} > (:intent this-users-conversation)) > > ([this-users-conversation salesforce-object-name] > {:pre [(map? this-users-conversation) > (string? salesforce-object-name)]} > (:intent this-users-conversation)) > > ([this-users-conversation salesforce-object-name name-of-attribute] > {:pre [(map? this-users-conversation) > (string? salesforce-object-name) > (string? name-of-attribute)]} > (:intent this-users-conversation)) > > ([this-users-conversation salesforce-object-name name-of-attribute > name-of-intent] > {:pre [(map? this-users-conversation) > (string? salesforce-object-name) > (keyword? name-of-attribute) > (string? name-of-intent)]} > name-of-intent)) > > #'user/discern > > user> (defmulti intent > > (fn [& args] > (apply discern args))) > > #'user/intent > > user> (defmethod intent nil [& args] (str "I got nil plus " args)) > > #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] > > user> (defmethod intent "query-salesforce-for-attribute" [& args] (str > "SQFFA " args)) > > #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] > > user> (defmethod intent :default [& args] (str "WAT? " args)) > > #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] > > user> (def this-users-conversation {}) > > #'user/this-users-conversation > > user> (intent this-users-conversation "Opportunity" :Name > "query-salesforce-for-attribute") > > "SQFFA ({} \"Opportunity\" :Name \"query-salesforce-for-attribute\")" > > user> (intent this-users-conversation "Opportunity" "Name") > > "I got nil plus ({} \"Opportunity\" \"Name\")" > > user> (intent {:intent "do-something"} "Opportunity" "Name") > > "WAT? ({:intent \"do-something\"} \"Opportunity\" \"Name\")" > > > > > Sean Corfield -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > > > > > From: <clo...@googlegroups.com <javascript:>> on behalf of Lawrence > Krubner > Reply-To: <clo...@googlegroups.com <javascript:>> > Date: Wednesday, September 30, 2015 at 5:33 PM > To: Clojure > Subject: can I use varargs in a multimethod? > > > >For maximum flexibility I wanted to use a multimethod, defined like this: > > > > > >(defmulti intent > > (fn [& args] > > (apply discern args))) > > > > > >This is how discern is defined: > > > >(defn- discern > > > > ([this-users-conversation] > > {:pre [(map? this-users-conversation)]} > > (:intent this-users-conversation)) > > > > ([this-users-conversation salesforce-object-name] > > {:pre [(map? this-users-conversation) > > (string? salesforce-object-name)]} > > (:intent this-users-conversation)) > > > > ([this-users-conversation salesforce-object-name name-of-attribute] > > {:pre [(map? this-users-conversation) > > (string? salesforce-object-name) > > (string? name-of-attribute)]} > > (:intent this-users-conversation)) > > > > ([this-users-conversation salesforce-object-name name-of-attribute > name-of-intent] > > {:pre [(map? this-users-conversation) > > (string? salesforce-object-name) > > (keyword? name-of-attribute) > > (string? name-of-intent)]} > > name-of-intent)) > > > > > >but then I call the multimethod like this: > > > >(intent this-users-conversation "Opportunity" :Name > "query-salesforce-for-attribute") > > > > > >and I get: > > > >:class clojure.lang.ArityException, > >:message "Wrong number of args (4) passed to: query/fn--65", > > > > > >Should I give up on this idea, or is there a way to make this work? > > > > > > -- 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.