insert-records is a function, so you should be able to just apply it?

(apply insert-records :blogs (map #(zipmap [:a :b :c :d] %)
                                  [[1 2 3 4] [5 6 7 8]]))

FWIW, the * notation around the parens makes it very difficult (for
me) to read the code example. Just write code as-is, and let the
reader notice that the parens are what's different (it's not hard).

It's also not clear whether you actually *mean* [here stars for "bold"
are okay because it isn't code] by the parens. Are you actually typing
that code in and seeing it doesn't work? That's because (a b), for any
a and b, means "call a as a function with b as its argument". The repl
prints seqs and lists with (a b c) notation, because it isn't worried
about you trying to execute them; but if you want to type a seq or a
list for the repl, you have to quote it or explicitly make a list of
it: (list a b) or '(a b) depending on whether you want a and b to be
evaluated.

There are a small number of functions that work on vectors but not
lists (or seqs in general), such as assoc. As a quick fix you could
convert the seq to a vector, but if you have code producing seqs that
wants to interact with code that consumes vectors, there are a number
of other solutions that might be right.

On May 31, 9:35 pm, mmwaikar <mmwai...@gmail.com> wrote:
> Hi,
>
> I've to use clojure.contrib.sql's insert-records fn.
>
> Usage: (insert-records table & records)
>
> Inserts records into a table. records are maps from strings or
> keywords (identifying columns) to values.
>
> So, for ex. this works -
> (clojure.contrib.sql/insert-records :blogs
>                                                 {:id 3 :title "third" :body 
> "third post"}
>                                                 {:id 4 :title "fourth" :body 
> "fourth post"})
>
> but this doesn't -
> (clojure.contrib.sql/insert-records :blogs
>                                                 *(*{:id 3 :title "third" 
> :body "third post"}
>                                                 {:id 4 :title "fourth" :body 
> "fourth post"}*)*)
>
> So, how do I retrieve individual maps from - (map #(zipmap [:a :b :c :d] %) 
> [[1 2 3 4] [5 6 7 8]]) [where :a :b etc. are columns and the second vector is 
> values]
> because the above gives me back - ({:d 4, :c 3, :b 2, :a 1} {:d 8, :c 7, :b 
> 6, :a 5}) which I cannot pass to the "insert-records" function.
>
> Also, I get confused as to why some functions work on [] but not on lists (). 
> In such cases, do I have to convert a list into a vector using something like 
> vec?
>
> Thanks,
> Manoj.

-- 
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

Reply via email to