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
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,
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
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
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
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
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
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
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
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
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
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
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
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
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,
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,
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
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
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
. 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
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
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
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
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
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
25 matches
Mail list logo