From: Tassilo Horn <tsdh@gnu.org>
To: Les Harris <les@lesharris.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Concern around use of eval
Date: Thu, 19 Mar 2015 09:00:06 +0100 [thread overview]
Message-ID: <87mw398lix.fsf@gnu.org> (raw)
In-Reply-To: <medrpv$a2h$1@ger.gmane.org> (Les Harris's message of "Wed, 18 Mar 2015 23:53:51 -0700")
Les Harris <les@lesharris.com> writes:
Hi Les,
> ,----
> | (defvar lh/labels '("label1" "label2" "label3"))
> |
> | (defmacro lh/gen-predicate (label)
> | `(defun ,(intern (concat "lh/" label "-p")) ()
> | (member ,label *lh/system-label-store*)))
> |
> | (defun lh/define-predicates ()
> | (dolist (label lh/labels)
> | (eval `(lh/gen-predicate ,label))))
> | (lh/define-predicates)
> `----
>
> Now this all works fine and I get my auto-generated predicates, so
> success. My question/concern/niggle is around the use of (eval) in
> lh/define-predicates. If I don't put eval in there then the defun the
> macro evaluates into never gets evaluated itself. Stylistically, is
> there a better way to do this or am I just being weird about (eval) and
> should just get over it?
Well, in case the `lh/label' value is available at compile-time then
`lh/define-predicates' can also be a macro and you can go like this:
--8<---------------cut here---------------start------------->8---
(defvar lh/labels '("label1" "label2" "label3"))
(defmacro lh/gen-predicate (label)
`(defun ,(intern (concat "lh/" label "-p")) ()
(member ,label *lh/system-label-store*)))
(defmacro lh/define-predicates ()
`(progn
,@(mapcar (lambda (label)
`(lh/gen-predicate ,label))
lh/labels)))
(lh/define-predicates)
--8<---------------cut here---------------end--------------->8---
But if you know your labels only at runtime, then I think there's no way
around using `eval'.
Bye,
Tassilo
next prev parent reply other threads:[~2015-03-19 8:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-19 6:53 Concern around use of eval Les Harris
2015-03-19 8:00 ` Tassilo Horn [this message]
[not found] ` <mailman.2302.1426752018.31049.help-gnu-emacs@gnu.org>
2015-03-19 8:12 ` Joost Kremers
2015-03-19 8:31 ` Tassilo Horn
[not found] ` <mailman.2305.1426753885.31049.help-gnu-emacs@gnu.org>
2015-03-20 19:54 ` Joost Kremers
2015-03-19 14:07 ` Stefan Monnier
2015-03-20 15:17 ` Thierry Volpiatto
2015-03-20 17:19 ` Bug in Elisp font-locking (was: Concern around use of eval) Tassilo Horn
2015-03-20 17:31 ` Bug in Elisp font-locking Stefan Monnier
2015-03-20 17:43 ` Drew Adams
2015-03-20 18:47 ` Tassilo Horn
2015-03-20 20:38 ` Stefan Monnier
2015-03-20 22:45 ` Tassilo Horn
2015-03-21 2:33 ` Stefan Monnier
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mw398lix.fsf@gnu.org \
--to=tsdh@gnu.org \
--cc=help-gnu-emacs@gnu.org \
--cc=les@lesharris.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).