Re: partial, but instead of args + additional, get additional + args

2011-10-23 Thread Meikel Brandmeyer
Hi,

Am 22.10.2011 um 20:49 schrieb Sean Corfield:

 I'm
 starting to think there's a nice, idiomatic solution lurking somewhere
 that wouldn't require an extra function...

The idiomatic solution is #(f % a1 a2 a3). I'm failing to see the issue with 
“nice” and “expressive”, but that is most likely just me.

Sincerely
Meikel

-- 
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: partial, but instead of args + additional, get additional + args

2011-10-23 Thread Ben Smith-Mannschott
On Sun, Oct 23, 2011 at 21:25, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 22.10.2011 um 20:49 schrieb Sean Corfield:

 I'm
 starting to think there's a nice, idiomatic solution lurking somewhere
 that wouldn't require an extra function...

 The idiomatic solution is #(f % a1 a2 a3). I'm failing to see the issue with 
 “nice” and “expressive”, but that is most likely just me.

I find myself reaching for partial when I could be using #(), I even
often find myself rejiggering the argument order of my own functions
to make them more useful in combination with partial.

But, honestly, I'm not quite sure why I have this preference. The
#(...) is arguably more readable since we're shown explicitly where
the argument goes, and yet I still find myself reaching for partial
and comp when I can make them fit. I mean, I like the fact that
partial and comp don't cause yet-another-tiny-class to be generated
every time they appear in code. But that doesn't seem like reason
enough. Am I just being too clever?

// Ben

 Sincerely
 Meikel

 --
 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 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: partial, but instead of args + additional, get additional + args

2011-10-23 Thread Sean Corfield
On Sun, Oct 23, 2011 at 1:04 PM, Ben Smith-Mannschott
bsmith.o...@gmail.com wrote:
 On Sun, Oct 23, 2011 at 21:25, Meikel Brandmeyer m...@kotka.de wrote:
 The idiomatic solution is #(f % a1 a2 a3). I'm failing to see the issue with 
 “nice” and “expressive”, but that is most likely just me.
 I find myself reaching for partial when I could be using #()

I was using #() and (fn..) extensively in my code until I noticed just
how many anonymous classes were being generated (we had a scenario
where we were repeatedly reloading the Clojure code - deliberately -
and of course ended up with thousands of these classes loaded!).
Understood it's fine in load-once-and-run scenarios.

When I brought this up on IRC, several folks said they felt the comp /
partial approach was nicer because it was point-free - as well as not
generating new classes (new instances, yes, new classes, no - right?).
Since then, I've almost eliminated the use of #() and (fn..) in our
code and, whilst more verbose initially in some cases, I'm actually
really liking the point-free style and it's letting me see new
opportunities for refactoring and simplification that I hadn't seen
previously (often triggered by encouraging me to pay more attention to
argument ordering so that my functions are more composable).

Given Meikel's 2009 blog post, I can understand why he might not
agree, but given that we have both - and -, it does seem like we
have a 'hole' - comp/partial and - go together but there's no
comp/??? to go with - and we have to resort to #(f % a1 a2 a3)...
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: partial, but instead of args + additional, get additional + args

2011-10-23 Thread Ben Smith-Mannschott
On Sun, Oct 23, 2011 at 23:53, Sean Corfield seancorfi...@gmail.com wrote:
 On Sun, Oct 23, 2011 at 1:04 PM, Ben Smith-Mannschott
 bsmith.o...@gmail.com wrote:
 On Sun, Oct 23, 2011 at 21:25, Meikel Brandmeyer m...@kotka.de wrote:
 The idiomatic solution is #(f % a1 a2 a3). I'm failing to see the issue 
 with “nice” and “expressive”, but that is most likely just me.
 I find myself reaching for partial when I could be using #()

 I was using #() and (fn..) extensively in my code until I noticed just
 how many anonymous classes were being generated (we had a scenario
 where we were repeatedly reloading the Clojure code - deliberately -
 and of course ended up with thousands of these classes loaded!).
 Understood it's fine in load-once-and-run scenarios.

 When I brought this up on IRC, several folks said they felt the comp /
 partial approach was nicer because it was point-free - as well as not
 generating new classes (new instances, yes, new classes, no - right?).
 Since then, I've almost eliminated the use of #() and (fn..) in our
 code and, whilst more verbose initially in some cases, I'm actually
 really liking the point-free style and it's letting me see new
 opportunities for refactoring and simplification that I hadn't seen
 previously (often triggered by encouraging me to pay more attention to
 argument ordering so that my functions are more composable).

 Given Meikel's 2009 blog post, I can understand why he might not
 agree, but given that we have both - and -, it does seem like we
 have a 'hole' - comp/partial and - go together but there's no
 comp/??? to go with - and we have to resort to #(f % a1 a2 a3)...

I propose partail ;-) While partial fills up the arguments from the
front, partail fills up the arguments from the back (the *tail*).
Plus, the spellings are so similar that it would cause no end of
confusion, particularly for people like me that swap letters every
once in a while, even when we don't mean to.

Ok, Cute name, but not a good name. Anyone got a better one?

// Ben


 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/
 Railo Technologies, Inc. -- http://www.getrailo.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)

 --
 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 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: partial, but instead of args + additional, get additional + args

2011-10-22 Thread Tyler Perkins
Just take an idea from Haskell (as usual!). Function 'flip' returns a
function taking its first two arguments in order opposite the given
function:

user (defn flip [f] (fn [a2 a1  more] (apply f a1 a2 more)))
#'user/flip
user (- 10 2 3)
5
user ((flip -) 2 10 3)
5
user ((partial  2000) 1000)
false
user ((partial (flip ) 2000) 1000)
true

-- 
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: partial, but instead of args + additional, get additional + args

2011-10-22 Thread Sean Corfield
On Sat, Oct 22, 2011 at 8:31 AM, Tyler Perkins thinks.outs...@gmail.com wrote:
 Just take an idea from Haskell (as usual!). Function 'flip' returns a
 function taking its first two arguments in order opposite the given
 function:

That works nicely for functions with two arguments but in this
situation I tend to have more than two arguments so #(f % a1 a2 a3) is
what I'd need.

After this and other threads, I'm beginning to think that need is a
smell of some sort and it signals that the order of the arguments (to
f) is wrong (to make it more amenable to partial application). I'm
starting to think there's a nice, idiomatic solution lurking somewhere
that wouldn't require an extra function...
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: partial, but instead of args + additional, get additional + args

2011-10-21 Thread Ulises
How about a potentially ugly workaround:

user (defn sum [  {:keys [x y]} ] (+ x y))
#'user/sum
user (sum :x 1 :y 2)
3
user (def inc-sum (partial sum :x 1))
#'user/inc-sum
user (inc-sum :y 1)
2
user (inc-sum :y 2)
3
user

I know this is a trivial example, but I do quite fancy named arguments
and being able to set them explicitly in partial.

U

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


partial, but instead of args + additional, get additional + args

2011-10-20 Thread Wilker
Hi guys,

I fall out in many situations that I want the partial, but inversed, a
simple example:

Let's say I wanna all primes bellow 2.000:

(take-while (partial  2000) primes)

In this case, that's ok, but I don't expressed myself write, I because I had
to use the oposite of  to create the partial, I wanna do something:

(take-while (rpartial  2000) primes)

In the case of  it's ok because they are reverse of each other, but in
some circustances there is no reverse function, and you finish can't be
using partial, instead you do like:

(take-while #( % 2000) primes)

I mean, there is no such function on default that works as reversed
arguments partial (appending partial arguments at end instead of beginning)?

If it don't, is not a good idea to have one?
---
Wilker Lúcio
http://about.me/wilkerlucio/bio
Kajabi Consultant
+55 81 82556600

-- 
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: partial, but instead of args + additional, get additional + args

2011-10-20 Thread Sean Corfield
On Thu, Oct 20, 2011 at 8:15 PM, Wilker wilkerlu...@gmail.com wrote:
 In the case of  it's ok because they are reverse of each other, but in
 some circustances there is no reverse function, and you finish can't be
 using partial, instead you do like:

 (take-while #( % 2000) primes)

 I mean, there is no such function on default that works as reversed
 arguments partial (appending partial arguments at end instead of beginning)?

I was expressing a need for exactly this function the other day on
IRC. I jokingly called it 'impartial' :)
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: partial, but instead of args + additional, get additional + args

2011-10-20 Thread Meikel Brandmeyer
Hi,

Am 21.10.2011 um 06:01 schrieb Sean Corfield:

 On Thu, Oct 20, 2011 at 8:15 PM, Wilker wilkerlu...@gmail.com wrote:
 
 (take-while #( % 2000) primes)
 
 I was expressing a need for exactly this function the other day on
 IRC. I jokingly called it 'impartial' :)

What is bad about #( % 2000)? In fact I would probably write the other case as 
#( 2000 %) instead of using partial. The only advantages of partial are a) 
that it acts like #(apply  2000 %) (to stay in the example) and b) that it 
generates one class less compared to #().

Sincerely
Meikel

-- 
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: partial, but instead of args + additional, get additional + args

2011-10-20 Thread Wilker
Hi Miekel,

The main reason is because I feel it is more expressive, and I really love
expressive code :)
---
Wilker Lúcio
http://about.me/wilkerlucio/bio
Kajabi Consultant
+55 81 82556600



On Thu, Oct 20, 2011 at 9:10 PM, Meikel Brandmeyer m...@kotka.de wrote:

 Hi,

 Am 21.10.2011 um 06:01 schrieb Sean Corfield:

  On Thu, Oct 20, 2011 at 8:15 PM, Wilker wilkerlu...@gmail.com wrote:
 
  (take-while #( % 2000) primes)
 
  I was expressing a need for exactly this function the other day on
  IRC. I jokingly called it 'impartial' :)

 What is bad about #( % 2000)? In fact I would probably write the other
 case as #( 2000 %) instead of using partial. The only advantages of partial
 are a) that it acts like #(apply  2000 %) (to stay in the example) and b)
 that it generates one class less compared to #().

 Sincerely
 Meikel

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