Dear list,

I have working code for 2 inputs, but I am trying to write an
idiomatic version, where the result is that a function named "read-
files-into-memory" takes a variable number of file names and parses
the json.  My code works well until I try to wrap my stand alone call
to map into my "read-files-into-memory" function.

My stand alone call that works correctly is: (map #(read-json-filename
%1) fnames)
However, putting this into a wrapper function doesn't appear to give
each item piecemeal and results in the java.io.FileReader complaint of
"No matching ctor" for the underlying call.

Here are the details:

;; paths to 2 little testing files
proj=> fnames
["/home/avram/devel/scratch/a.json" "/home/avram/devel/scratch/
b.json"]

;; function that can read one file
proj=> (defn read-json-filename
  [ filename ]
  (clojure.contrib.json/read-json (FileReader. filename )))
#'proj/read-json-filename

;; Proof of concept: it works when passed a vector of filenames
proj=> (map #(read-json-filename %1) fnames)
({:metric1 {:section "a1", :runid "run-a", :value "123"}, :metric2
{:section "a2", :runid "run-a", :value "123.45"}, :metric3 {:section
"a3", :runid "run-a", :value "[1,2,3,4,5,6,7,8,9]"}} {:metric1
{:section "b1", :runid "run-b", :value "456"}, :metric2 {:section
"b2", :runid "run-b", :value "789.1011"}, :metric3 {:section
"b3", :runid "run-b", :value "[11,21,31,41,51,61,71,81,91]"}})

;; Intended to be a wrapper that calls map like above..
proj=> (defn read-files-into-memory
  [ & filenames ]
  (print filenames)
  (map #(read-json-filename %1) filenames))
#'proj/read-files-into-memory

;; …but it doesn't work
proj=> (read-files-into-memory fnames)
java.lang.IllegalArgumentException: No matching ctor found for class
java.io.FileReader

I thought the wrapper version was identical to the stand alone call,
but apparently not.


What changes are needed in "read-files-into-memory" ?


Many thanks,
Avram

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