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: Pascal J. Bourguignon
Subject: Re: Nested mapcar* application and possibly some variation of Y combinator
Date: Wed, 28 Mar 2012 19:21:29 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Swami Tota Ram Shankar <tota_ram@india.com> writes:

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

If you quote the lambda list, you prevent the ccompiler to compile the
anonymous function.  Why do you want to slow down you code like that?

Why do you call the function mapcar* ? 
There's no car in '[1 2 3...7] to map over.
Only cons cells have car slots, and since lists are built of cons cells, 
car can be applied to lists, to get the first element.  But car cannot
be applied to vectors.


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

What about: [[1 2 3] 4 [5 [6 7]]] ?
What about: [[1 2 3] (4 5 [6 7] 8 9)] ?
What about: [[1 2 3] #s(hash-table size 65 test eql rehash-size 1.5
                        rehash-threshold 0.8 data (:a 10 :b 11))] ?


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


reply via email to

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