Re: trouble using nested map fn

2010-08-25 Thread Glen Rubin
I'm glad my question generated so much discussion! Thank you all for the suggestions...it's all good stuff trying to wrap my head around and improve my facility with clojure. On Aug 24, 1:27 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On 24 Aug., 03:08, gary ng garyng2...@gmail.com wrote:

trouble using nested map fn

2010-08-23 Thread Glen Rubin
I am trying to write a fn to correlate 2 signals using 3 nested map fn. I have 2 collections of data. THe first group of signals called target looks something like this. target: ( (1,2,3,4) (2,3,4,5) ...) The second collection is called signal and looks like this: signal: (

Re: trouble using nested map fn

2010-08-23 Thread Luka Stojanovic
On Mon, 23 Aug 2010 17:26:44 +0200, Glen Rubin rubing...@gmail.com wrote: I am trying to write a fn to correlate 2 signals using 3 nested map fn. I have 2 collections of data. THe first group of signals called target looks something like this. target: ( (1,2,3,4) (2,3,4,5) ...) The second

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 8:31 AM, Luka Stojanovic li...@magrathea.rs wrote: It's not about nested maps, but about nested anonymous functions: if you nest anonimous functions you must use (fn [] ...) like: (map (fn [t s] (map #(map * %1 %2) t s)) target signal) This has me question, how useful

Re: trouble using nested map fn

2010-08-23 Thread Btsai
Ah, so this is the context for your previous thread about multiplying lists. Re-using some of the code from that thread: (def target [[1 2 3 4] [2 3 4 5]]) (def signal [[[1 2 3 4] [2 3 4 5] [3 4 5 6]] [[2 3 4 5] [3 4 5 6] [4 5 6 7]]]) (defn correlate [target signal] (let [mult-lists (fn [x

Re: trouble using nested map fn

2010-08-23 Thread Joop Kiefte
uses like #(first %) keeps the code cleaner on the other hand, for more complicated things I would really not recommend the short form 2010/8/23 gary ng garyng2...@gmail.com: On Mon, Aug 23, 2010 at 8:31 AM, Luka Stojanovic li...@magrathea.rs wrote: It's not about nested maps, but about nested

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 8:50 AM, Joop Kiefte iko...@gmail.com wrote: uses like #(first %) keeps the code cleaner Is that the same as just 'first' like : (map first [[1 2] [3 4]]) (map #(first %) [[1 2] [3 4])) -- You received this message because you are subscribed to the Google Groups

Re: trouble using nested map fn

2010-08-23 Thread Joop Kiefte
bad example =/ Yes, it is but you get the gist I hope better example: #(first (sort %)) ;) 2010/8/23 gary ng garyng2...@gmail.com: On Mon, Aug 23, 2010 at 8:50 AM, Joop Kiefte iko...@gmail.com wrote: uses like #(first %) keeps the code cleaner Is that the same as just 'first' like : (map

Re: trouble using nested map fn

2010-08-23 Thread Cameron
Again with the bad examples but... (map #(even? %) coll) is faster than (map (partial even?) coll) So it's at least got that going for it. (I know this SHOULD be written as (map even? coll)) On Aug 23, 1:59 pm, Michael Gardner gardne...@gmail.com wrote: On Aug 23, 2010, at 11:13 AM, Luka

Re: trouble using nested map fn

2010-08-23 Thread Alan
Really? I would be interested to hear why; is it maybe because partial has to take any number of arguments and then (apply even? args)? I've taken to using partial when I can, precisely because of the difficulty of nesting anonymous functions, and while performance isn't a big deal for me I'm

Re: trouble using nested map fn

2010-08-23 Thread Cameron Pulsford
The difference is not HUGE, but in a critical section it might be a valid micro-optimization. I'd also be interested to know why, but I bet you're assumption of apply being thrown in the mix is probably pretty close to true. user= (time (dotimes [_ 1e6] (doall (map #(filter even? %) (for [i

Re: trouble using nested map fn

2010-08-23 Thread Randy Hudson
Well, #(= lo % hi) is to my mind much more readable than (fn [x] (= lo x hi)), especially embedded in another form or two (as it would be). On Aug 23, 11:48 am, gary ng garyng2...@gmail.com wrote: On Mon, Aug 23, 2010 at 8:31 AM, Luka Stojanovic li...@magrathea.rs wrote: It's not about nested

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 8:26 AM, Glen Rubin rubing...@gmail.com wrote: I am trying to write a fn to correlate 2 signals using 3 nested map fn.  I have 2 collections of data.  THe first group of signals called target looks something like this. target: ( (1,2,3,4) (2,3,4,5) ...) The second

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 5:41 PM, Randy Hudson randy_hud...@mac.com wrote: Well, #(= lo % hi) is to my mind much more readable than (fn [x] (= lo x hi)), especially embedded in another form or two (as it would be). that may be true. though this IMO is partly due to the (=) construct's argument

Re: trouble using nested map fn

2010-08-23 Thread David Sletten
There may be some value in the intellectual exercise to try something like your solution, but I think this is far more tractable if you use meaningful variable names: (map (fn [group scalars] (map (fn [trial] (map (fn [signal scalar] (* signal scalar)) trial scalars)) group)) signal target)

Re: trouble using nested map fn

2010-08-23 Thread Meikel Brandmeyer
Hi, On 24 Aug., 03:08, gary ng garyng2...@gmail.com wrote: (map #(for [s %2] (map * %1 s)) target signal) Though personally I still think the %2 %1 is a bit confusing.- Zitierten Text ausblenden - If you don't like it, don't use it.You can always give things meaningful names. (for