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 22:36:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

On 2013-01-07, Barry Margolin wrote:

>> I construct TLV (table-len-val) structs in string.
>>
>> Is it possible to omit "eval" from second line by using some sugar code:
>>
>>   (setq binstr-len 4)
>>   (setq binstr (eval `(unibyte-string ?s binstr-len ,@(make-list binstr-len
>>   ?x))))
>>   (assert (eq (+ 2 binstr-len) (length binstr)))
>>
>> Another solution:
>>
>>   (setq binstr (concat (unibyte-string ?s binstr-len) (make-list binstr-len
>>   ?x)))
>>
>> Or "apply" stands for this purpose(??):
>>
>>   (setq binstr (apply 'unibyte-string ?s binstr-len (make-list binstr-len
>>   ?x)))
>
> The "apply" solution is usually the correct way to do it.

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"?

-- 
Best regards!




reply via email to

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