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 wrote: > Hi, > > On 24 Aug., 03:08, gary ng wrote: > > > (map #(for [s %2] (map *

Re: trouble using nested map fn

2010-08-23 Thread Meikel Brandmeyer
Hi, On 24 Aug., 03:08, gary ng 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 [[signals target] (map v

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

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 5:41 PM, Randy Hudson 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 order. This i

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 8:26 AM, Glen Rubin 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 collectio

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 wrote: > On Mon, Aug 23, 2010 at 8:31 AM, Luka Stojanovic wrote: > > It's not about nested maps, but about nested anonymous f

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

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 curi

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 wrote: > On Aug 23, 2010, at 11:13 AM, Luka Stojanovic wrote: > >

Re: trouble using nested map fn

2010-08-23 Thread Michael Gardner
On Aug 23, 2010, at 11:13 AM, Luka Stojanovic wrote: > On Mon, 23 Aug 2010 18:01:13 +0200, Joop Kiefte wrote: > >> bad example =/ >> >> Yes, it is >> >> but you get the gist I hope >> >> better example: #(first (sort %)) ;) >> > > (comp first sort) > > and #(some-fn x %) can be written as

Re: trouble using nested map fn

2010-08-23 Thread Luka Stojanovic
On Mon, 23 Aug 2010 18:01:13 +0200, Joop Kiefte wrote: bad example =/ Yes, it is but you get the gist I hope better example: #(first (sort %)) ;) (comp first sort) and #(some-fn x %) can be written as (partial some-fn x) which leaves #(some-fn % x) as case not trivial with other syntax

Re: trouble using nested map fn

2010-08-23 Thread Adam Burry
Benny is right. This problem is *much* easier if you break it up and do it in baby steps. You can start very simply, get it working, and then factor as you like. For example, in Scheme notation (I'm not a clojure guy yet): (map * '(1 2 3) '(1 2 3)) -> (1 4 9) (map (lambda (x) (map * '(1 2 3) x)) '

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 9:01 AM, Joop Kiefte wrote: > bad example =/ > > Yes, it is > > but you get the gist I hope > > better example: #(first (sort %)) ;) > Yes, though I think it is still cleaner if it is expressed as: (map (comp first sort) [[3 2] [4 5]]) In other words, if it is a single ar

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 : > On Mon, Aug 23, 2010 at 8:50 AM, Joop Kiefte wrote: >> uses like #(first %) keeps the code cleaner >> > Is that the same as just 'first' like : > > (map first [[1 2] [3 4]]) > > (ma

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 8:50 AM, Joop Kiefte 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 "Clojure" group. To

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 : > On Mon, Aug 23, 2010 at 8:31 AM, Luka Stojanovic wrote: >> It's not about nested maps, but about nested anonymous functions: if you >> nest

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

Re: trouble using nested map fn

2010-08-23 Thread gary ng
On Mon, Aug 23, 2010 at 8:31 AM, Luka Stojanovic 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 the #(...) fo

Re: trouble using nested map fn

2010-08-23 Thread Luka Stojanovic
On Mon, 23 Aug 2010 17:26:44 +0200, Glen Rubin 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 collection is calle

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: ( ((1,2,3,4)(2,3,4,