all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: Oleksandr Gavenko <gavenkoa@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: "Backquote constructs" to "splice" values without "eval".
Date: Tue, 08 Jan 2013 02:40:29 +0530	[thread overview]
Message-ID: <87ip78ya0q.fsf@gmail.com> (raw)
In-Reply-To: <87sj6cspbs.fsf@gavenkoa.example.com> (Oleksandr Gavenko's message of "Mon, 07 Jan 2013 22:36:23 +0200")

Oleksandr Gavenko <gavenkoa@gmail.com> writes:

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

(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.
-- 



  reply	other threads:[~2013-01-07 21:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.16855.1357563071.855.help-gnu-emacs@gnu.org>
2013-01-07 15:02 ` "Backquote constructs" to "splice" values without "eval" Barry Margolin
2013-01-07 20:36   ` Oleksandr Gavenko
2013-01-07 21:10     ` Jambunathan K [this message]
2013-01-07 21:47       ` Oleksandr Gavenko
2013-01-08  5:48         ` Jambunathan K
2013-01-08  5:51           ` Jambunathan K
     [not found]   ` <mailman.16874.1357591009.855.help-gnu-emacs@gnu.org>
2013-01-07 20:51     ` Barry Margolin
2013-01-07 12:50 Oleksandr Gavenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ip78ya0q.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=gavenkoa@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.