Re: (map f coll) using memfn

2008-10-16 Thread Timothy Pratley
Slam dunk Rich! Yes I can see that is much better. Thanks for taking the time to understand what I was trying to do instead of what I thought I was trying to do :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clo

Re: (map f coll) using memfn

2008-10-16 Thread Rich Hickey
On Oct 15, 11:13 pm, Timothy Pratley <[EMAIL PROTECTED]> wrote: > Thanks so much for all the replies, that showed the way to what I > wanted (simplified example using substring): > > (defn lazy-self [me] > ((fn rfib [a] (lazy-cons a (rfib a))) me)) > (defmacro map-obj [jobj jmeth argbinds & co

Re: (map f coll) using memfn

2008-10-16 Thread Timothy Pratley
Neat tip. Applying that, this is what I've come up with: (defn jcall [obj name & args] (clojure.lang.Reflector/invokeInstanceMethod obj (str name) (if args (to-array args) clojure.lang.RT/EMPTY_ARRAY))) (defn map-obj [jobj jmeth coll & colls] (apply map #(apply jcall jobj jmeth %&) coll c

Re: (map f coll) using memfn

2008-10-15 Thread mb
Hi, On 16 Okt., 05:13, Timothy Pratley <[EMAIL PROTECTED]> wrote: > Just a few follow on questions... > 1) Is there any way to do away with the input bindings altogether? map > doesn't need input bindings, but memfn does. I don't quite grasp why > they are needed for memfn, or how to construct an

Re: (map f coll) using memfn

2008-10-15 Thread Timothy Pratley
Thanks so much for all the replies, that showed the way to what I wanted (simplified example using substring): (defn lazy-self [me] ((fn rfib [a] (lazy-cons a (rfib a))) me)) (defmacro map-obj [jobj jmeth argbinds & colls] `(map (memfn ~jmeth [EMAIL PROTECTED]) (lazy-self ~jobj) [EMAIL PROTEC

Re: (map f coll) using memfn

2008-10-15 Thread mb
Hi, On 15 Okt., 19:09, "Graham Fawcett" <[EMAIL PROTECTED]> wrote: > > (map f coll (range (count coll))) > > Rather than (range (count coll)), I would use (iterate inc 0), which > incurs no overhead for counting the argument. There is not only the overhead of counting, (count coll) might also d

Re: (map f coll) using memfn

2008-10-15 Thread Jim Menard
On Wed, Oct 15, 2008 at 1:09 PM, Graham Fawcett <[EMAIL PROTECTED]> wrote: > > On Wed, Oct 15, 2008 at 8:21 AM, Jim Menard <[EMAIL PROTECTED]> wrote: >> >> On Wed, Oct 15, 2008 at 7:46 AM, Timothy Pratley >> <[EMAIL PROTECTED]> wrote: >>> >>> Can I get some help with (map f coll)... >>> >>> What I

Re: (map f coll) using memfn

2008-10-15 Thread Rich Hickey
On Oct 15, 11:26 am, "Jim Menard" <[EMAIL PROTECTED]> wrote: > On Wed, Oct 15, 2008 at 8:21 AM, I wrote: > > map can take more than one argument. If it has N arguments, it calls f > > with N arguments, each taken from the Nth value of each collection. > > Too many "N"s. Restated, map takes a fun

Re: (map f coll) using memfn

2008-10-15 Thread Graham Fawcett
On Wed, Oct 15, 2008 at 8:21 AM, Jim Menard <[EMAIL PROTECTED]> wrote: > > On Wed, Oct 15, 2008 at 7:46 AM, Timothy Pratley > <[EMAIL PROTECTED]> wrote: >> >> Can I get some help with (map f coll)... >> >> What I want to do is map a java function that takes 2 arguments over a >> list >> where the

Re: (map f coll) using memfn

2008-10-15 Thread Jim Menard
On Wed, Oct 15, 2008 at 8:21 AM, I wrote: > map can take more than one argument. If it has N arguments, it calls f > with N arguments, each taken from the Nth value of each collection. Too many "N"s. Restated, map takes a function f and N collections, each of which should have the same number of

Re: (map f coll) using memfn

2008-10-15 Thread Jim Menard
On Wed, Oct 15, 2008 at 7:46 AM, Timothy Pratley <[EMAIL PROTECTED]> wrote: > > Can I get some help with (map f coll)... > > What I want to do is map a java function that takes 2 arguments over a > list > where the first argument is the index into the list itself > and the second argument is taken

(map f coll) using memfn

2008-10-15 Thread Timothy Pratley
Can I get some help with (map f coll)... What I want to do is map a java function that takes 2 arguments over a list where the first argument is the index into the list itself and the second argument is taken from the list The problem being map uses a function of 1 argument. Does that mean I nee