From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Concern around use of eval Date: Thu, 19 Mar 2015 09:00:06 +0100 Message-ID: <87mw398lix.fsf@gnu.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1426752040 9264 80.91.229.3 (19 Mar 2015 08:00:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Mar 2015 08:00:40 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Les Harris Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 19 09:00:30 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YYVNV-0003Ni-Qh for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Mar 2015 09:00:29 +0100 Original-Received: from localhost ([::1]:37606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYVNU-0005lH-H9 for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Mar 2015 04:00:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYVND-0005jx-7d for help-gnu-emacs@gnu.org; Thu, 19 Mar 2015 04:00:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYVN9-0000Ge-Nc for help-gnu-emacs@gnu.org; Thu, 19 Mar 2015 04:00:11 -0400 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:34332) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYVN9-0000DE-IX for help-gnu-emacs@gnu.org; Thu, 19 Mar 2015 04:00:07 -0400 Original-Received: from thinkpad-t440p (dhcp132.uni-koblenz.de [141.26.71.132]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by deliver.uni-koblenz.de (Postfix) with ESMTPSA id EAFD01A8488; Thu, 19 Mar 2015 09:00:06 +0100 (CET) Mail-Followup-To: Les Harris , help-gnu-emacs@gnu.org In-Reply-To: (Les Harris's message of "Wed, 18 Mar 2015 23:53:51 -0700") User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 141.26.64.15 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:103208 Archived-At: Les Harris 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