Re: Apply elements in a vector as arguments to function

2013-03-29 Thread Marko Topolnik
ClojureDocs currently show just the original docstring followed by user-contributed examples. I think a lot of readers would benefit from somethig like this: apply (apply f args* argseq) *Scripture:* Applies fn f to the argument list formed by prepending args to argseq. *Interpretation: *The fi

Re: Apply elements in a vector as arguments to function

2013-03-27 Thread Marko Topolnik
On Wednesday, March 27, 2013 12:42:43 PM UTC+1, Ryan wrote: > If a developer cannot figure out how to do X from the docs, she should >> complain about it >> instead of assuming it's perfectly normal to spend time reading the >> source to figure out >> how to use something. > > > I generally agre

Re: Apply elements in a vector as arguments to function

2013-03-27 Thread Ryan
> > If a developer cannot figure out how to do X from the docs, she should > complain about it > instead of assuming it's perfectly normal to spend time reading the source > to figure out > how to use something. I generally agree with this, but not all code authors are willing to listen to yo

Re: Apply elements in a vector as arguments to function

2013-03-27 Thread Jim foo.bar
On 27/03/13 03:13, Michael Klishin wrote: Complain loudly to maintainers on this list that their documentation has gaps and they should clarify this and that. The idea that people should read the source to get reasonably straightforward stuff done is wrong and does a lot of long term damage to

Re: Apply elements in a vector as arguments to function

2013-03-27 Thread Michael Klishin
2013/3/27 Ryan > I believe Jim meant to check the source to figure out how does it work, > not that the way it's implemented is the most proper way to implement it. > If that's not what you wanted to point out can you please explain? > If a developer cannot figure out how to do X from the docs,

Re: Apply elements in a vector as arguments to function

2013-03-27 Thread Marko Topolnik
Now that Michael mentioned it, the docstring of *apply* says Applies fn f to the argument list formed by prepending intervening > arguments to args. I challenge any Clojure newbie to decipher this Hickeyism for me. This is of course no exception; most of clojure.core is like that. I can perso

Re: Apply elements in a vector as arguments to function

2013-03-27 Thread Ryan
> > The idea that people should read the source to get reasonably > straightforward stuff done is wrong and does a lot of long term damage to > the community. I believe Jim meant to check the source to figure out how does it work, not that the way it's implemented is the most proper way to im

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Michael Klishin
2013/3/27 Jim - FooBar(); > aaa see? always check the docs first and the sources second (if > available)...I should have done that as well :) Definitely don't just check the sources and think it's something normal. Complain loudly to maintainers on this list that their documentation has gaps a

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Ryan
Well, I did check em but It wasn't clear to me that I could pass a vector; I thought that was only for aliasing. Oh well, it happens I guess :) Thanks again everybody! On Tuesday, March 26, 2013 10:30:48 PM UTC+2, Jim foo.bar wrote: > > aaa see? always check the docs first and the sources secon

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Jim - FooBar();
aaa see? always check the docs first and the sources second (if available)...I should have done that as well :) Jim On 26/03/13 20:28, Ryan wrote: Ah damn, you are right! Sorry if I wasted anyone's time :) At least I learned that apply was the way to go in my original post On Tuesday, March

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Ryan
Ah damn, you are right! Sorry if I wasted anyone's time :) At least I learned that apply was the way to go in my original post On Tuesday, March 26, 2013 10:23:10 PM UTC+2, Cedric Greevey wrote: > > The docs there seem to imply that fields takes a keyword or a vector, > rather than a keyword or

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Jim - FooBar();
;;from the website you linked (/fields/ [:firstname :first]:last :address.state) ;; you can alias a field using a vector of [field alias] Your vector argument should look like this: [[:firstname :first]:last :address.state] or like this (if you're not aliasing): [:firstname :last :

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Cedric Greevey
The docs there seem to imply that fields takes a keyword or a vector, rather than a keyword or keywords. Try just (fields fields-vector), without the "apply". On Tue, Mar 26, 2013 at 4:12 PM, Ryan wrote: > Thank you guys for your answer. apply was the first thing I used but I got > the followin

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Ryan
Thank you guys for your answer. apply was the first thing I used but I got the following error: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to > clojure.lang.Associative and i thought i am not going the right way. What i am more specifically trying to do is this: http:/

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Jim - FooBar();
On 26/03/13 19:28, Ryan wrote: apply the elements of my vector as arguments to the function you said it yourself in your first post... :) 'apply' is what you're looking for! Jim -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Alan Thompson
Essentially, apply just removes the parens (or brackets) from your list of args and creates the original function call: (apply + [1 2 3]) -> (+ 1 2 3) Alan Thompson On Tue, Mar 26, 2013 at 12:49 PM, Alan Thompson wrote: > Apply works for any number of args: > > (apply + [1 2 3 4 5]) > > He

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Max Penet
You are mistaken :) try: (apply str [:a :b :c]) (apply str [:a :b :c :d :e]) > (doc apply) - clojure.core/apply ([f args] [f x args] [f x y args] [f x y z args] [f a b c d & args]) Applies fn f to the argument list formed by prepending intervening arguments to args. nil

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Michael Klishin
2013/3/26 Ryan > Thanks Michael, but If i am not mistaken, your example only works with a > vector with two elements. What if we have an unknown number of vector > elements? > My apologies if that wasn't clear on my first post. > If your function's signature allows for & rest arguments, it will

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Alan Thompson
Apply works for any number of args: (apply + [1 2 3 4 5]) He just gave you an example inline function of 2 args since that was the original example. Alan Thompson On Tue, Mar 26, 2013 at 12:44 PM, Ryan wrote: > Thanks Michael, but If i am not mistaken, your example only works with a > vector

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Marko Topolnik
Have you tried (apply my-function [:foo :bar]) yet? Because *apply* is exactly what you are looking for; to make sure, read its docstring. On Tuesday, March 26, 2013 8:44:49 PM UTC+1, Ryan wrote: > > Thanks Michael, but If i am not mistaken, your example only works with a > vector with two eleme

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Ryan
Thanks Michael, but If i am not mistaken, your example only works with a vector with two elements. What if we have an unknown number of vector elements? My apologies if that wasn't clear on my first post. On Tuesday, March 26, 2013 9:38:55 PM UTC+2, Michael Klishin wrote: > > > 2013/3/26 Ryan >

Re: Apply elements in a vector as arguments to function

2013-03-26 Thread Michael Klishin
2013/3/26 Ryan > What i am trying to do is to apply the elements of my vector as arguments > to the function. How can I achieve this? user=> (apply (fn [a b] (println a b)) [:a :b]) :a :b nil -- MK http://github.com/michaelklishin http://twitter.com/michaelklishin -- -- You received this

Apply elements in a vector as arguments to function

2013-03-26 Thread Ryan
Hello all, I have been searching and searching on how to do this but I am failing miserably. I am trying to do a pretty simply thing actually. I have the following vector: [:foo :bar] and a function that takes keywords as arguments, like so: (my-function :foo :bar & more) What i am trying