Re: call to idiomatic loop works as stand alone but not when wrapped in my function
n 15/04/2011 01:21, Avram wrote: Yes, I am missing a way to turn the [ filenames] into something like name1 name2 … You also missed Joost's answer =) Use apply for this : user (+ 1 2 3) 6 user (apply + (list 1 2 3)) 6 So in your case : (apply read-files-into-memory fnames) hth, Sacha -- 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
Re: call to idiomatic loop works as stand alone but not when wrapped in my function
I would do it by making read-files-into-memory take a single argument, a list of filenames, rather than N arguments, each of which is a filename. Just drop the in the function's definition and you should be done. On Apr 14, 4:21 pm, Avram aav...@me.com wrote: Yes, I am missing a way to turn the [ filenames] into something like name1 name2 … How might this be done? (I am not certain what type this would be, a stringified version of each item in the sequence, not a sequence itself! ) (defn read-files-into-memory [ filenames ] (print filenames) (map #(read-json-filename %1) filenames)) 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
Re: call to idiomatic loop works as stand alone but not when wrapped in my function
Thank-you, I think that works for me! I do need the to be able to take in a variable number of arguments, but it looks like I can call vec to convert this to a vector, then call the read-files-into- memory function that now will take a single argument. Such an elegant language but difficult to search for things like args or % or to find answers ;) Best, Avram On Apr 15, 1:10 am, Alan a...@malloys.org wrote: I would do it by making read-files-into-memory take a single argument, a list of filenames, rather than N arguments, each of which is a filename. Just drop the in the function's definition and you should be done. On Apr 14, 4:21 pm, Avram aav...@me.com wrote: Yes, I am missing a way to turn the [ filenames] into something like name1 name2 … How might this be done? (I am not certain what type this would be, a stringified version of each item in the sequence, not a sequence itself! ) (defn read-files-into-memory [ filenames ] (print filenames) (map #(read-json-filename %1) filenames)) 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
Re: call to idiomatic loop works as stand alone but not when wrapped in my function
You never need when you are defining your own functions. It's equivalent to declaring that your function takes one argument, a vector, and then always wrapping up in a vector whatever args you want to use. On Apr 15, 11:05 am, Avram aav...@me.com wrote: Thank-you, I think that works for me! I do need the to be able to take in a variable number of arguments, but it looks like I can call vec to convert this to a vector, then call the read-files-into- memory function that now will take a single argument. Such an elegant language but difficult to search for things like args or % or to find answers ;) Best, Avram On Apr 15, 1:10 am, Alan a...@malloys.org wrote: I would do it by making read-files-into-memory take a single argument, a list of filenames, rather than N arguments, each of which is a filename. Just drop the in the function's definition and you should be done. On Apr 14, 4:21 pm, Avram aav...@me.com wrote: Yes, I am missing a way to turn the [ filenames] into something like name1 name2 … How might this be done? (I am not certain what type this would be, a stringified version of each item in the sequence, not a sequence itself! ) (defn read-files-into-memory [ filenames ] (print filenames) (map #(read-json-filename %1) filenames)) 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
call to idiomatic loop works as stand alone but not when wrapped in my function
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
Re: call to idiomatic loop works as stand alone but not when wrapped in my function
(defn read-files-into-memory [ filenames ] (print filenames) (map #(read-json-filename %1) filenames)) The [ filenames] argument spec turns all the arguments given into a sequence. You're not passing the filenames as separate arguments, but as a vector, so you either have to change that: (read-files-into-memory name1 name2 ..) or you need to use apply: (apply read-files-into-memory fnames) -- 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
Re: call to idiomatic loop works as stand alone but not when wrapped in my function
Yes, I am missing a way to turn the [ filenames] into something like name1 name2 … How might this be done? (I am not certain what type this would be, a stringified version of each item in the sequence, not a sequence itself! ) (defn read-files-into-memory [ filenames ] (print filenames) (map #(read-json-filename %1) filenames)) 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