help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nested mapcar* application and possibly some variation of Y combinat


From: WJ
Subject: Re: Nested mapcar* application and possibly some variation of Y combinator
Date: 29 Mar 2012 08:24:25 GMT
User-agent: XanaNews/1.18.1.6

Swami Tota Ram Shankar wrote:

> Dear elispWizards,
> 
> Consider the following command to halve every element in a vector or a
> list
> 
> (mapcar* '(lambda(x) (* 0.5 x)) '[1 2 3 4 5 6 7] )     --->   (0.5 1.0
> 1.5 2.0 2.5 3.0 3.5)
> 
> Now, I intend to vary it so that it operated like this on a singly
> nested list
> 
> (mapcar* '(lambda(x) (* 0.5 x)) '[[1 2 3] [4 5 6 7]] )     --->
> ((0.5 1.0 1.5) (2.0 2.5 3.0 3.5))
> 
> It would be nice if this can be accomplished without opening the
> nested list or vector and nesting it again.
> 
> I could not put the mapcar* inside the lambda ... maybe made some
> simple mistake. I dont have a strong enough intuition to say if this
> is possible or not.
> 

(mapcar (lambda(s) (mapcar (apply-partially '* 0.5) s)) [[1 2][3 4]])
 ==> ((0.5 1.0) (1.5 2.0))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]