Reduce vs. Comp

2014-05-07 Thread Mark Watson
What is the difference between: (reduce #(%2 %) 6 [(partial + 12) (partial * -1)]) and ((apply comp [(partial * -1) (partial + 12)]) 6) Using reduce *looks* nicer to me, but I feel like I'm re-implementing comp. Their performance is also the same (go inlining!). -- You received this message

Re: Reduce vs. Comp

2014-05-07 Thread Mike Fikes
I agree with the re-implementing comp sentiment. It reminds me of *A tutorial on the universality and expressiveness of fold http://www.cs.nott.ac.uk/~gmh/fold.pdf *where, essentially lots of standard functions can be defined in terms of reduce which could be considered primitive. In fact,

Re: Reduce vs. Comp

2014-05-07 Thread John Mastro
Hi, Mike Fikes mikefi...@me.com wrote: In fact, section 5 of that document defines comp as a reduce involving the identify function in some way. (Now, I want to re-read this paper, but translated into Clojure.) Here's one definition of comp in terms of reduce: (defn comp [ fs] (reduce (fn

Re: Reduce vs. Comp

2014-05-07 Thread Timothy Baldridge
If you read the source for comp, you'll find that anything more than 3 args gets turned into something like reduce anyways: (defn comp Takes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a variable number of args, applies the rightmost of

Re: Reduce vs. Comp

2014-05-07 Thread Gary Johnson
Reduce is indeed a swiss-army knife for functional programming over sequences. Of course, in this particular case (i.e., apply a sequence of functions in order to an initial value), Clojure's threading operators are the idiomatic way to go. (- 6 (+ 12) (* -1)) Cheers, ~Gary -- You

Re: Reduce vs. Comp

2014-05-07 Thread Mark Watson
I agree. I guess I was specifically thinking of a list of functions where the length of the list, and the functions themselves, are defined at run-time. Which would lead to some nasty code using the threading macros. (Unless someone has an example of this not being the case) On Wednesday, May

Re: - vs comp

2009-10-18 Thread Stuart Halloway
I find the suite of -, -, anonymous functions, partial, and comp sufficient for my needs, with each having its place. My only grumble is that partial is a lot of characters. I would love a one-character alternative, if it could be reasonably intuitive. Stu On Oct 16, 10:22 pm, Sean Devlin

Re: - vs comp

2009-10-18 Thread B Smith-Mannschott
On Sun, Oct 18, 2009 at 20:04, Stuart Halloway stuart.hallo...@gmail.com wrote: I find the suite of -, -, anonymous functions, partial, and comp sufficient for my needs, with each having its place. My only grumble is that partial is a lot of characters. I would love a one-character

Re: - vs comp

2009-10-18 Thread Sean Devlin
I've been using and p, respectively. On Oct 18, 2:21 pm, B Smith-Mannschott bsmith.o...@gmail.com wrote: On Sun, Oct 18, 2009 at 20:04, Stuart Halloway stuart.hallo...@gmail.com wrote: I find the suite of -, -, anonymous functions, partial, and comp sufficient for my needs, with each

Re: - vs comp

2009-10-18 Thread Robert Fischer
The F# language does partial application through calling the function: if you don't supply enough arguments, they're partially applied. The | syntax is for backwards (object-y) partial application: let f x y = ... let g = f 1 let h = 1 | f The | operator is built-in in F#, but in OCaml (my

Re: - vs comp

2009-10-17 Thread James Reeves
On Oct 17, 3:22 am, Sean Devlin francoisdev...@gmail.com wrote: I have an idea in my head, and I can't quite put all the details together.  The intent with of this posting is to start a healthy debate of the merits of - vs. comp.  I know people on this list will think of something. It seems

Re: - vs comp

2009-10-17 Thread James Reeves
On Oct 17, 4:55 am, samppi rbysam...@gmail.com wrote: Personally, I can go either way—I just kind of wish that there was a consistent practice for the placement of the most important argument, whether it's first or last, in both core and contrib. Well, defining the most important argument can

Re: - vs comp

2009-10-17 Thread Laurent PETIT
2009/10/17 James Reeves weavejes...@googlemail.com On Oct 17, 4:55 am, samppi rbysam...@gmail.com wrote: Personally, I can go either way—I just kind of wish that there was a consistent practice for the placement of the most important argument, whether it's first or last, in both core and

Re: - vs comp

2009-10-17 Thread Meikel Brandmeyer
Hi. Am 17.10.2009 um 13:25 schrieb James Reeves: Well, defining the most important argument can be tricky. However, it would be nice if there were map and filter variants that could be used with -. There is also -. (- some-seq (filter predicate) (map function) (remove

Re: - vs comp

2009-10-17 Thread Sean Devlin
Hmmm... good point about java interop. Didn't consider that. On Oct 17, 3:44 am, Timothy Pratley timothyprat...@gmail.com wrote: On Oct 17, 1:22 pm, Sean Devlin francoisdev...@gmail.com wrote: Given these reasons, I'd like to make a proposal. Contrib should be centered around closures,

Re: - vs comp

2009-10-17 Thread Sean Devlin
Okay, comp on its own is not comparable to -, good point. Once you add partial, I think a more direct comparison is possible. (let [ comp p partial (( (p filter predicate) (p map function) (p remove other-predicate)) some-seq)) This is a lot closer to the new -. Anyway,

Re: - vs comp

2009-10-17 Thread Wilson MacGyver
Kinda off topic. I didn't realize - has been introduced. Is there a list of new forms that's been introduced since 1.0? Thanks On Sat, Oct 17, 2009 at 9:17 AM, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/10/17 James Reeves weavejes...@googlemail.com On Oct 17, 4:55 am, samppi

Re: - vs comp

2009-10-17 Thread Stuart Sierra
On Oct 16, 10:22 pm, Sean Devlin francoisdev...@gmail.com wrote: In order to generate closures, every function should take parameters first, and data at the end, so that they work well with partial. It's really hard to come up with a consistent practice that works well for all scenarios. Even

- vs comp

2009-10-16 Thread Sean Devlin
I have an idea in my head, and I can't quite put all the details together. The intent with of this posting is to start a healthy debate of the merits of - vs. comp. I know people on this list will think of something. After designing my own Clojure libraries for a while, I've come

Re: - vs comp

2009-10-16 Thread samppi
. comp.  I know people on this list will think of something. After designing my own Clojure libraries for a while, I've come to a conclusion in the - vs. comp debate. I think comp partial is a better choice than -, because they return a closure. I believe working with closures have the following

Re: - vs comp

2009-10-16 Thread John Harrop
On Fri, Oct 16, 2009 at 11:55 PM, samppi rbysam...@gmail.com wrote: Don't forget about the third piece of the puzzle, #() (and fn). Whenever I need to create a function using -, I just do #(- % ...). It's about as much typing as (comp ...). Personally, I can go either way—I just kind of wish

Re: - vs. comp

2009-04-01 Thread Laurent PETIT
of the comp function? I happily concede that there exist nicer ways to achieve this goal, but the question I wanted to raise concerned the benefits of using - vs comp or vice-versa. Kev Kev --~--~-~--~~~---~--~~ You received this message because you are subscribed

Re: - vs. comp

2009-04-01 Thread Rayne
of the comp function? I happily concede that there exist nicer ways to achieve this goal, but the question I wanted to raise concerned the benefits of using - vs comp or vice-versa. Kev Kev --~--~-~--~~~---~--~~ You received this message because you are subscribed

- vs. comp

2009-03-31 Thread kkw
to raise concerned the benefits of using - vs comp or vice-versa. Kev Kev --~--~-~--~~~---~--~~ 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 To unsubscribe

Re: - vs. comp

2009-03-31 Thread David Nolen
from appearance, are there any benefits to using - instead of the comp function? I happily concede that there exist nicer ways to achieve this goal, but the question I wanted to raise concerned the benefits of using - vs comp or vice-versa. Kev Kev