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: Oleksandr Gavenko
Subject: Re: "Backquote constructs" to "splice" values without "eval".
Date: Mon, 07 Jan 2013 23:47:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

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.

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)

If 'some' is complicated you need:

  (let* ( (region some) (beg (car region)) (end (cdr region)) )
      (another x beg end y)
    )

-- 
Best regards!




reply via email to

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