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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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, 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.)

On Wednesday, May 7, 2014 9:17:46 AM UTC-4, Mark Watson wrote:

 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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 [result f]
(fn [ args]
  (result (apply f args
  identity
  fs))

It's probably a bit clearer with one of the anonymous functions pulled
out and named:

(defn comp [ fs]
  (letfn [(chain [result f]
(fn [ args]
  (f (apply result args]
(reduce chain identity fs)))

They're less efficient than clojure.core/comp's implementation, but I
love the versatility of {reduce,fold,whatever}.

Best regards,

John

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 fns to the args, the next
  fn (right-to-left) to the result, etc.
  {:added 1.0
   :static true}
  ([] identity)
  ([f] f)
  ([f g]
 (fn
   ([] (f (g)))
   ([x] (f (g x)))
   ([x y] (f (g x y)))
   ([x y z] (f (g x y z)))
   ([x y z  args] (f (apply g x y z args)
  ([f g h]
 (fn
   ([] (f (g (h
   ([x] (f (g (h x
   ([x y] (f (g (h x y
   ([x y z] (f (g (h x y z
   ([x y z  args] (f (g (apply h x y z args))
  ([f1 f2 f3  fs]
(let [fs (reverse (list* f1 f2 f3 fs))]
  (fn [ args]
(loop [ret (apply (first fs) args) fs (next fs)]
  (if fs
(recur ((first fs) ret) (next fs))
ret))


On Wed, May 7, 2014 at 10:34 AM, John Mastro john.b.mas...@gmail.comwrote:

 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 [result f]
 (fn [ args]
   (result (apply f args
   identity
   fs))

 It's probably a bit clearer with one of the anonymous functions pulled
 out and named:

 (defn comp [ fs]
   (letfn [(chain [result f]
 (fn [ args]
   (f (apply result args]
 (reduce chain identity fs)))

 They're less efficient than clojure.core/comp's implementation, but I
 love the versatility of {reduce,fold,whatever}.

 Best regards,

 John

 --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.




-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 7, 2014 1:00:17 PM UTC-4, Gary Johnson wrote:

 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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 clojure.core is inconsistent in this regard
 -- the sequence fns take the seq at the end, the collection functions
 (like assoc) take the collection first.

 Whichever way you design your functions, half the time the arguments
 will be in the wrong place for what someone wants to do.  If you want
 a purely compositional style, the only way to do it is to only allow
 single-argument functions, a la Haskell.

 -SS
 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 alternative, if it could be reasonably intuitive.


F# uses  for functional composition and | for partial evaluation.
Both as infix operators, of course. Perhaps they'd work for clojure's
prefix syntax?

(def  comp)
(def | partial)

what do you think?

 Stu

 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 clojure.core is inconsistent in this regard
 -- the sequence fns take the seq at the end, the collection functions
 (like assoc) take the collection first.

 Whichever way you design your functions, half the time the arguments
 will be in the wrong place for what someone wants to do.  If you want
 a purely compositional style, the only way to do it is to only allow
 single-argument functions, a la Haskell.

 -SS
 


 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 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.

 F# uses  for functional composition and | for partial evaluation.
 Both as infix operators, of course. Perhaps they'd work for clojure's
 prefix syntax?

 (def  comp)
 (def | partial)

 what do you think?



  Stu

  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 clojure.core is inconsistent in this regard
  -- the sequence fns take the seq at the end, the collection functions
  (like assoc) take the collection first.

  Whichever way you design your functions, half the time the arguments
  will be in the wrong place for what someone wants to do.  If you want
  a purely compositional style, the only way to do it is to only allow
  single-argument functions, a la Haskell.

  -SS
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 background), | can be 
defined easily enough:
let (|) x f = f x

~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, Grails Persistence with GORM and GSQL!
http://www.smokejumperit.com/gormbook


B Smith-Mannschott 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 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.

 
 F# uses  for functional composition and | for partial evaluation.
 Both as infix operators, of course. Perhaps they'd work for clojure's
 prefix syntax?
 
 (def  comp)
 (def | partial)
 
 what do you think?
 
 Stu

 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 clojure.core is inconsistent in this regard
 -- the sequence fns take the seq at the end, the collection functions
 (like assoc) take the collection first.

 Whichever way you design your functions, half the time the arguments
 will be in the wrong place for what someone wants to do.  If you want
 a purely compositional style, the only way to do it is to only allow
 single-argument functions, a la Haskell.

 -SS

 
  
 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 to me you're comparing apples to oranges.  - is a macro for
making code more readable under certain circumstances, whilst comp
performs function composition. They have very different uses.

- James
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 be tricky. However,
it would be nice if there were map and filter variants that could be
used with -.

- James
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 contrib.

 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 -.


FYI, though I haven't used it yet, I've noticed the introduction of - in
core.clj

(- data (map my-fn) (filter my-pred))

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 other-predicate))

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


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, not -.

 Hi Sean,

 - seems to work nicely for java interop in ways that comp does not. I
 think it has its place.

 (defn full-screen
   Enables full-screen mode
   [#^Window window]
   (later
     (-
       (GraphicsEnvironment/getLocalGraphicsEnvironment)
       .getDefaultScreenDevice
       (.setFullScreenWindow window

 I don't think there is an easy composition equivalent. Java tends to
 have quite a few of these chain calls.

 Are there any particular examples you are refering to?

 Regards,
 Tim.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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, I see now what the main point is.  The main point is where
does the data go?  I like - putting data in the end is a huge step
forward.  It makes the libraries designed to use it more flexible,
because it supports both coding styles.

On Oct 17, 7:52 am, Meikel Brandmeyer m...@kotka.de wrote:
 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 other-predicate))

 Sincerely
 Meikel

  smime.p7s
 3KViewDownload
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 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 be tricky. However,
 it would be nice if there were map and filter variants that could be
 used with -.

 FYI, though I haven't used it yet, I've noticed the introduction of - in
 core.clj

 (- data (map my-fn) (filter my-pred))



 




-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 clojure.core is inconsistent in this regard
-- the sequence fns take the seq at the end, the collection functions
(like assoc) take the collection first.

Whichever way you design your functions, half the time the arguments
will be in the wrong place for what someone wants to do.  If you want
a purely compositional style, the only way to do it is to only allow
single-argument functions, a la Haskell.

-SS
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



- 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 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 advantages

* It just works with higher order functions, like map or filter.
* comp, like any other function, can be swapped out. As long as the
result is a closure, the rest of the code will just work. This makes
swapping out a monad more straightforward.
* comp  partial can be applied to a list, - cannot.

Given these reasons, I'd like to make a proposal. Contrib should be
centered around closures, not -.

In order to generate closures, every function should take parameters
first, and data at the end, so that they work well with partial. When
possible, higher order functions should be given preference over
macros.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: - vs comp

2009-10-16 Thread samppi

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 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.

On Oct 16, 7:22 pm, 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.

 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 advantages

 * It just works with higher order functions, like map or filter.
 * comp, like any other function, can be swapped out. As long as the
 result is a closure, the rest of the code will just work. This makes
 swapping out a monad more straightforward.
 * comp  partial can be applied to a list, - cannot.

 Given these reasons, I'd like to make a proposal. Contrib should be
 centered around closures, not -.

 In order to generate closures, every function should take parameters
 first, and data at the end, so that they work well with partial. When
 possible, higher order functions should be given preference over
 macros.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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 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.


While we're at it, let's not forget the fourth piece of the puzzle: swap!,
alter, send, and friends, which work best if functions put the data first
and parameters after. If the parameters come first, all of them need to be
wrapped: instead of (send agent foo param1 param2), say, you need (send
agent #(foo param1 param2 %)). Yuck!

(Irony: - is also like swap!, alter, and their friends in this regard.)

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: - vs. comp

2009-04-01 Thread Laurent PETIT
While we speak about function composition (or not),
you can also use the partial function creator to obtain point-free (no
need for anonymous function with formal argument declaration or use) code:

And with the use of comp, you could define the function without even
explicitly naming any formal argument :-) :

1:7 user= (def deep-csv (comp (partial apply println)
(partial interpose , )
seq-utils/flatten))
#'user/deep-csv
1:10 user= (deep-csv '((1 2 3) (4 5 6)))
1 ,  2 ,  3 ,  4 ,  5 ,  6
nil

For one-shot expression threading, I agree with David that - would be more
approriate, though the need to enclose the anonymous function definitions in
extraneous parenthesis is not so lisible, even with short forms of anonymous
function definitions:

(defn deep-csv [mr]  (- mr
   flatten
   (#(interpose ,  %))
   (#(apply println %

My 0,02€,

-- 
Laurent

2009/4/1 kkw kevin.k@gmail.com


 Hi folks,

I have some code where I wanted to:
 - take a list of stuff (which includes another list inside)
 - use 'seq-utils/flatten' to flatten the list
 - use 'interpose' to add comma-delimiting strings between the elements
 - print out the results, thereby creating comma-delimited output

I may choose between:

  ((comp
  (fn [x] (apply println x))
  (fn [x] (interpose ,  x))
  seq-utils/flatten)
 mr)

 OR

  (- mr
seq-utils/flatten
((fn [x] (interpose ,  x)))
((fn [x] (apply println x

And I found the - notation marginally easier to interpret and
 understand. Apart 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
 


--~--~-~--~~~---~--~~
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 this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: - vs. comp

2009-04-01 Thread Rayne

comp seems more appropriate here.

On Mar 31, 11:52 pm, kkw kevin.k@gmail.com wrote:
 Hi folks,

     I have some code where I wanted to:
 - take a list of stuff (which includes another list inside)
 - use 'seq-utils/flatten' to flatten the list
 - use 'interpose' to add comma-delimiting strings between the elements
 - print out the results, thereby creating comma-delimited output

     I may choose between:

               ((comp
                   (fn [x] (apply println x))
                   (fn [x] (interpose ,  x))
                   seq-utils/flatten)
                  mr)

 OR

               (- mr
                 seq-utils/flatten
                 ((fn [x] (interpose ,  x)))
                 ((fn [x] (apply println x

     And I found the - notation marginally easier to interpret and
 understand. Apart 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
--~--~-~--~~~---~--~~
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 this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



- vs. comp

2009-03-31 Thread kkw

Hi folks,

I have some code where I wanted to:
- take a list of stuff (which includes another list inside)
- use 'seq-utils/flatten' to flatten the list
- use 'interpose' to add comma-delimiting strings between the elements
- print out the results, thereby creating comma-delimited output

I may choose between:

  ((comp
  (fn [x] (apply println x))
  (fn [x] (interpose ,  x))
  seq-utils/flatten)
 mr)

OR

  (- mr
seq-utils/flatten
((fn [x] (interpose ,  x)))
((fn [x] (apply println x

And I found the - notation marginally easier to interpret and
understand. Apart 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
--~--~-~--~~~---~--~~
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 this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: - vs. comp

2009-03-31 Thread David Nolen
comp creates a new function that you can store.
- threads a value through a series of expressions.

On Wed, Apr 1, 2009 at 12:52 AM, kkw kevin.k@gmail.com wrote:


 Hi folks,

I have some code where I wanted to:
 - take a list of stuff (which includes another list inside)
 - use 'seq-utils/flatten' to flatten the list
 - use 'interpose' to add comma-delimiting strings between the elements
 - print out the results, thereby creating comma-delimited output

I may choose between:

  ((comp
  (fn [x] (apply println x))
  (fn [x] (interpose ,  x))
  seq-utils/flatten)
 mr)

 OR

  (- mr
seq-utils/flatten
((fn [x] (interpose ,  x)))
((fn [x] (apply println x

And I found the - notation marginally easier to interpret and
 understand. Apart 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
 


--~--~-~--~~~---~--~~
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 this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---