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 *
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
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
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
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
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
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
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
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:
>
>
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
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
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)) '
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
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
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
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
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]
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
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
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,
20 matches
Mail list logo