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

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

Re: "Backquote constructs" to "splice" values without "eval".


From: Jambunathan K
Subject: Re: "Backquote constructs" to "splice" values without "eval".
Date: Tue, 08 Jan 2013 11:18:05 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Oleksandr Gavenko <address@hidden> writes:

> On 2013-01-07, Jambunathan K wrote:
>
>>> I also start thinking about "apply" with several list inside it:
>>>
>>>   (apply '+ 1 '(2) '(3 4))
>>>
>>> But above expression fail (only last arg expanded as list of args). To 
>>> resolve
>>> this issue I use expression:
>>>
>>>   (apply '+ 1 (append '(2) '(3 4)))
>>>
>>> But how about expression with atoms between (??):
>>>
>>>   '(1) 2 '(3 4)
>>>
>>> I write non-linear code:
>>>
>>>   (apply '+ (append '(1) (cons 2 '(3 4))))
>>>
>>> How to avoid call to "cons"?
>>
>> (apply '+ (loop for x in '(1 (2) (3 4))
>>              collect (if (numberp x) x (apply '+ x))))
>>
>> There are also other predicates that you can use.  For eg., atom, consp,
>> listp.
>
> Your trick work because + is associative operation.
>
> I just start from example from 'apply' doc-string.

It is not clear to me what you are saying.  But I know that people who
are in Agra are searching for Taj Mahal, 99.9% of the cases.  You may
not visit Taj but atleast you can walk around Agra.  One is no better
than the other.

> Consider example when 'some' func return region and 'another' require beg/end
> pair:
>
>   (defun some () ... (list beg end))
>   (defun another (x beg end y) ...)
>
> I think that this code ugly:
>
>   (another x (car (some)) (cdr (some)) y)

Talking about ugly, while architecting something on a small scale is
sure way to get lost.

Aesthetics is over-rated.

ps: This is not a criticism of what you are doing but an observation
from my own experience.

> If 'some' is complicated you need:
>
>   (let* ( (region some) (beg (car region)) (end (cdr region)) )
>       (another x beg end y)
>     )

destructuring-bind, pcase, pcase*
-- 



reply via email to

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