Re: Confused about comp

2012-12-17 Thread Peter West
Thanks. That's much better. On Monday, December 17, 2012 8:53:22 PM UTC+10, Dick Davies wrote: > > > If you're using leiningen (2 at least, maybe 1?) then a > > (user/clojuredocs apply) > > is a much better "how do I drive this thing?" than a straight (doc ...) > call. > -- You received thi

Re: Confused about comp

2012-12-17 Thread Dick Davies
On 16 December 2012 10:59, Peter West wrote: > This effect is, on the face of it, unpredictable: you just have to know that > that is what apply does. Users of clojure learn that pretty quickly. I've > just learned it. Doc doesn't help. > >>> user=> (doc apply) If you're using leiningen (2 at l

Re: Confused about comp

2012-12-16 Thread Marko Topolnik
> However, the fact that you can write funcall so easily as #(%1 %2) > illustrates that funcall adds no real expressiveness to the language, > whereas apply is really fundamental to being able to pass lists to > multi-arg functions. It's hard to imagine how to write apply at all if it > were

Re: Confused about comp

2012-12-16 Thread Mark Engelberg
On Sun, Dec 16, 2012 at 10:04 AM, Marko Topolnik wrote: > > Well, why don't you start with my example? Try rewriting this without OP's > *apply*, implemented here as #(%1 %2). > > (defn apply-curried [f & args] (reduce #(%1 %2) f args)) > > > To avoid confusion, I'm going to refer to the OP's con

Re: Confused about comp

2012-12-16 Thread Marko Topolnik
> As for your suggestion of a (funcall f [i]) that behaves just like (f > [i]), I can't imagine any possible purpose for that in Clojure. Why would > you not just write (f [i])? > Well, why don't you start with my example? Try rewriting this without OP's * apply*, implemented here as #(%1 %

Re: Confused about comp

2012-12-16 Thread Mark Engelberg
On Sun, Dec 16, 2012 at 2:59 AM, Peter West wrote: So it sounds like you just thought apply was something other than the list->arguments adapter that it is. One of the best resources for learning about clojure's functions is clojuredocs.org. Most of the functions are accompanied by a number of

Re: Confused about comp

2012-12-16 Thread Marko Topolnik
> If you are looking, for some reason I can't imagine at the moment, for a > function that acts just like a funcall, so that > (funcall f [i]) is exactly equivalent to (f [i]), I guess you are out of > luck. > I can give you a reason: applying a curried function. On first sight that may seem

Re: Confused about comp

2012-12-16 Thread Marko Topolnik
> > Users of clojure learn that pretty quickly. I've just learned it. Doc > doesn't help. > user=> (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

Re: Confused about comp

2012-12-16 Thread Peter West
Thanks again. I do get it. I'm not saying that apply has effects other than the result it returns. No, it's not a side-effect; it doesn't change something in the environment in passing. What it changes is the expected result, if you expect that, as Rich Hickey is supposed to have written, (appl

Re: Confused about comp

2012-12-15 Thread Mark Engelberg
On Sat, Dec 15, 2012 at 3:58 PM, Peter West wrote: > But it can't, can it? In this context (apply f [i]) with respect to (f i)* > apply *has *side-effects*! > This doesn't really make any sense. There are no side effects here. I think maybe you just don't understand what apply does. Let me t

Re: Confused about comp

2012-12-15 Thread Peter West
Hi Mark and Baishampayan, I can see what difference it makes, but I can't get a handle on the rationale. For instance, I found this discussion: http://stackoverflow.com/questions/1257028/why-should-i-use-apply-in-clojure It starts with a quote from a Rich Hickey blog post, as follows. > A big d

Re: Confused about comp

2012-12-15 Thread Alan Malloy
Nonsense. Why would that be any faster? (join coll) is defined as (apply str coll). On Saturday, December 15, 2012 12:21:45 PM UTC-8, Marek Šrank wrote: > > ...which should be also a lot faster :) > > On Saturday, December 15, 2012 5:44:01 PM UTC+1, Armando Blancas wrote: >> >> (comp (partial app

Re: Confused about comp

2012-12-15 Thread Marek Šrank
...which should be also a lot faster :) On Saturday, December 15, 2012 5:44:01 PM UTC+1, Armando Blancas wrote: > > (comp (partial apply str) (partial filter #{\a})) >> > > Or, (comp join (partial filter #{\a})) > > -- You received this message because you are subscribed to the Google Groups "

Re: Confused about comp

2012-12-15 Thread Armando Blancas
> > (comp (partial apply str) (partial filter #{\a})) > Or, (comp join (partial filter #{\a})) -- 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 moder

Re: Confused about comp

2012-12-15 Thread Baishampayan Ghose
An example will make it clear for you... (str ) => (str '("foo" "bar" "baz")) (apply str ) => (str "foo" "bar" "baz) Hope this helps. -BG On Sat, Dec 15, 2012 at 3:48 PM, Peter West wrote: > Thanks Baishampayan. > > I'm still puzzled about this though, because (doc str) says that with one > a

Re: Confused about comp

2012-12-15 Thread Marko Topolnik
> I'm still puzzled about this though, because (doc str) says that with one > argument x, str returns x.toString(). What it returns is > "clojure.lang.LazySeq@fe1" > > So it seems to be returning a lazy sequence. Why is the function not > simply applied? Other functions are "applied" simple by

Re: Confused about comp

2012-12-15 Thread Peter West
On Saturday, 15 December 2012 17:42:05 UTC+10, puzzler wrote: > > (I took the liberty of replacing #(= \a %) with #{\a}) > > On Fri, Dec 14, 2012 at 11:37 PM, Mark Engelberg > > > wrote: > >> (comp (partial apply str) (partial filter #{\a})) >> > > Puzzler, Your change replaces the single argume

Re: Confused about comp

2012-12-15 Thread Peter West
Thanks Baishampayan. I'm still puzzled about this though, because (doc str) says that with one argument x, str returns x.toString(). What it returns is "clojure.lang.LazySeq@fe1" So it seems to be returning a lazy sequence. Why is the function not simply applied? Other functions are "applied" s

Re: Confused about comp

2012-12-15 Thread Peter West
On Saturday, 15 December 2012 18:09:13 UTC+10, Peter West wrote: > > > > On Saturday, 15 December 2012 17:42:05 UTC+10, puzzler wrote: >> >> (I took the liberty of replacing #(= \a %) with #{\a}) >> >> On Fri, Dec 14, 2012 at 11:37 PM, Mark Engelberg wrote: >> >>> (comp (partial apply str) (parti

Re: Confused about comp

2012-12-15 Thread Baishampayan Ghose
The apply is needed here because filter is going to return a sequence of strings and you really want to `apply' str on it. -BG On Sat, Dec 15, 2012 at 1:39 PM, Peter West wrote: > A couple of questions, if I may. > > In (partial apply str) why the apply? > > Given the apply, why the partial?

Re: Confused about comp

2012-12-15 Thread Peter West
On Saturday, 15 December 2012 17:42:05 UTC+10, puzzler wrote: > > (I took the liberty of replacing #(= \a %) with #{\a}) > > On Fri, Dec 14, 2012 at 11:37 PM, Mark Engelberg > > > wrote: > >> (comp (partial apply str) (partial filter #{\a})) >> > > You're most welcome. Thank you for this. A co

Re: Confused about comp

2012-12-14 Thread Mark Engelberg
(I took the liberty of replacing #(= \a %) with #{\a}) On Fri, Dec 14, 2012 at 11:37 PM, Mark Engelberg wrote: > (comp (partial apply str) (partial filter #{\a})) > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to

Re: Confused about comp

2012-12-14 Thread Mark Engelberg
(comp (partial apply str) (partial filter #{\a})) -- 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. T

Confused about comp

2012-12-14 Thread Peter West
I want to compose and apply a function as follows: A> (= ( "abBcdAa">) "aa") I can filter the argument using filter #(= \a %) . If I (def s (filter #(= \a %) "abBcdAa")) I get (\a \a\). If I (str s) I get "clojure.lang.LazySeq@fe1" If I (apply str s) i get "aa" But what I am trying to do is A