There's also 'for' (defn my-function [foo-id a-keyword a-list] (for [m a-list] {:foo_id foo-id (keyword a-keyword) (:BAR_KEY m)}))
On Sun, Mar 31, 2013 at 12:57 AM, JvJ <kfjwhee...@gmail.com> wrote: > ...even cheezier, use do > #(do {:foo %}) > > > On Saturday, 30 March 2013 23:58:31 UTC-4, JvJ wrote: >> >> Here's a cheezy hack, use identity. >> >> #(identity {:foo %}) >> >> On Thursday, 28 March 2013 17:51:10 UTC-4, Ryan wrote: >>> >>> Thanks for your explanation Jonathan. I am still a bit confused however >>> what is the proper solution here. Should i use an anonymous function >>> instead to do what I want or can it be done with the #() syntax? >>> >>> Hyphens is my preferred way as well, but, those keys represent sql >>> columns which they use underscore so I gotta go with underscores in order >>> code to match them :) >>> >>> Ryan >>> >>> On Thursday, March 28, 2013 11:24:38 PM UTC+2, Jonathan Fischer Friberg >>> wrote: >>>> >>>> It's because the #() syntax always calls the content as a function. >>>> >>>> So #(...) is the same as (fn [] (...)). In your case, >>>> #({:foo_id foo-id (keyword a-keyword) (:BAR_KEY %)}) >>>> is the same as: >>>> (fn [%] ({:foo_id foo-id (keyword a-keyword) (:BAR_KEY %)})) >>>> Note the extra () around {}. In other words, your map is called >>>> as a function. >>>> >>>> Maps can normally be called as functions, like this: >>>> ({:hello :world} :hello) >>>> => :world >>>> That's why you get the "Wrong number of args" error >>>> (and not a "a map is not a function" error). >>>> Hope that makes sense. >>>> >>>> Btw, hyphen is normally used instead of underscore >>>> in both variables and keywords. Just a slight style >>>> "issue", but maybe you had your reasons. :) >>>> >>>> Jonathan >>>> >>>> >>>> On Thu, Mar 28, 2013 at 10:16 PM, Ryan <areka...@gmail.com> wrote: >>>> >>>>> Hello! >>>>> >>>>> I am having a small issue with a hash-map initialization and I am >>>>> failing to understand why. I have the following situation: >>>>> >>>>> (def a-list '({:BAR_KEY bar-value}, {:BAR_KEY another-value})) >>>>> >>>>> >>>>> (defn my-function [foo-id a-keyword a-list] >>>>> >>>>> (map #({:foo_id foo-id (keyword a-keyword) (:BAR_KEY %)}) a-list)) >>>>>> >>>>> >>>>> So, by running the above function like this: >>>>> >>>>> (my-function 5 "my_keyword" a-list) >>>>> >>>>> >>>>> I get the following error: >>>>> >>>>> *clojure.lang.ArityException: Wrong number of args (0) passed to: >>>>>> PersistentArrayMap* >>>>> >>>>> >>>>> I am trying to get the following result: >>>>> >>>>> ({:foo_id 5 :my_keyword bar-value}, {:foo_id 5 :my_keyword >>>>> another-value}) >>>>> >>>>> Any ideas? I have played around in repl for the last 2 hrs but I >>>>> haven't found the proper way to do this. >>>>> >>>>> Thank you for your time :) >>>>> >>>>> -- >>>>> -- >>>>> 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<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/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>>> . >>>>> >>>>> >>>>> >>>> >>>> -- > -- > 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. > > > -- -- 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.