Re: call to idiomatic loop works as stand alone but not when wrapped in my function

2011-04-16 Thread Phlex

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

2011-04-15 Thread Alan
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

2011-04-15 Thread Avram
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

2011-04-15 Thread Alan
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


Re: call to idiomatic loop works as stand alone but not when wrapped in my function

2011-04-14 Thread Joost
(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

2011-04-14 Thread Avram
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