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 wrote: > On Sun, Oct 23, 2011 at 1:04 PM, Ben Smith-Mannschott > wrote: >> On Sun, Oct 23, 2011 at 21:25, Meikel Brandmeyer wrote: >>> The idiomatic solution is #(f % a1 a2 a3). I'm failing to see the issue >>> with “nice” and “expressive”, but that

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 wrote: > On Sun, Oct 23, 2011 at 21:25, Meikel Brandmeyer 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

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

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 li

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

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)

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

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 wrote: > Hi, > > Am 21.10.2011 um 06:01 schrieb Sean C

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

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

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 part