Hmm, okay, so if "apply" unpacks all the arguments and feeds them all to my 
anonymous function, then this should work:

          (apply #([& everything] println first everything) @visitors)


but instead I get:

Unable to resolve symbol: & in this context
  [Thrown class java.lang.RuntimeException]


Please note, I ask this only out of intellectual curiosity. In my code I'll 
always use "map" in this circumstance. But I want to understand what apply 
really does, and I'm clearly missing something.






On Tuesday, July 17, 2012 3:13:04 PM UTC-4, Mark Rathwell wrote:
>
> > your apply will end up doing sometihng like this: 
> > (#(println %1) "stu" "mary" "lawrence") 
> > 
> > since apply takes @visitors as a collection and passes each item as an 
> > argument to the function you give it. 
>
> In other words, apply essentially unpacks the collection and passes 
> the items as individual arguments to the specified function.  str 
> takes any number of arguments, so it works well with apply in your 
> case.  Your anonymous function is a one-argument function, but apply 
> sends all items in your collection as arguments, and if your 
> collection contains more than one element then that will be the wrong 
> number of arguments. 
>
> map is mapping the specified function to each element in the 
> collection, one at a time, and returning a collection of the results. 
> apply is calling the function once, but with all elements in the 
> collection as the arguments and returning the result of that one 
> function call. 
>
> On Tue, Jul 17, 2012 at 2:35 PM, Jack Moffitt <j...@metajack.im> wrote: 
> > 
> > > So far, everything is working as I thought. But I also thought that 
> apply 
> > > let me run a function on everything in a sequence. Other than "str", I 
> could 
> > > not get this to work: 
> > > 
> > > user> (apply #(println %1) @visitors) 
> > 
> > I think you are looking for direct invocation: 
> > 
> > (#(println %1) @visitors) 
> > 
> > your apply will end up doing sometihng like this: 
> > (#(println %1) "stu" "mary" "lawrence") 
> > 
> > since apply takes @visitors as a collection and passes each item as an 
> > argument to the function you give it. 
> > 
> > jack. 
> > 
> > -- 
> > 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 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