On Sat, Jun 4, 2016 at 1:45 AM, James Reeves <ja...@booleanknot.com> wrote:
> You can do it with a macro. > > - James > > On 3 June 2016 at 22:22, Steven Zhou <zzuoh...@gmail.com> wrote: > >> Is it possible to write down a function do the following? >> >> (defn foo >> [input] >> .... >> ) >> >> (def x "Hello") >> (def y "Clojure") >> >> (foo [x y]) >> => {:x "Hello" :y "Clojure"} >> > This seems to do what you want: (defmacro foo [vars] (let [keys_ (mapv keyword vars)] `(zipmap ~keys_ ~vars))) Note the difference between ~(mapv keyword vars) & ~vars. The former maps (keyword) over a vector of symbols, then resolves their value (which is themselves). The latter resolves the vector of symbols directly, each element in turn gets resolved to their respective definitions. If you rewrite this to use a (foo [& vars] ...) and be called as (foo x y), I think it would be easier to see what's happening. > >> >> Regards, >> -Steven >> >> -- >> 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. > -- Kind Regards, Atamert Ölçgen ◻◼◻ ◻◻◼ ◼◼◼ www.muhuk.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/d/optout.