From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: emacs lisp - unable to write a function maker Date: Fri, 16 Sep 2011 07:06:13 -0700 Message-ID: <47D4EF93ED6C47B8AD53845AECED59D4@us.oracle.com> References: <87pqj0q2wo.fsf@ambire.localdomain> <87iposlshu.fsf@ericabrahamsen.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1316182008 7759 80.91.229.12 (16 Sep 2011 14:06:48 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 16 Sep 2011 14:06:48 +0000 (UTC) To: "'Eric Abrahamsen'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 16 16:06:44 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R4Z40-0004Nw-1K for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Sep 2011 16:06:44 +0200 Original-Received: from localhost ([::1]:34167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4Z3z-0006pB-BL for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Sep 2011 10:06:43 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:36817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4Z3r-0006oN-S6 for help-gnu-emacs@gnu.org; Fri, 16 Sep 2011 10:06:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R4Z3m-0000Wy-CM for help-gnu-emacs@gnu.org; Fri, 16 Sep 2011 10:06:35 -0400 Original-Received: from acsinet15.oracle.com ([141.146.126.227]:27560) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4Z3m-0000WW-7V for help-gnu-emacs@gnu.org; Fri, 16 Sep 2011 10:06:30 -0400 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p8GE6Nde009074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 16 Sep 2011 14:06:25 GMT Original-Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p8GE6MUc010637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 16 Sep 2011 14:06:23 GMT Original-Received: from abhmt116.oracle.com (abhmt116.oracle.com [141.146.116.68]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p8GE6HJG022440; Fri, 16 Sep 2011 09:06:17 -0500 Original-Received: from dradamslap1 (/10.159.62.142) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 16 Sep 2011 07:06:17 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <87iposlshu.fsf@ericabrahamsen.net> Thread-Index: Acx0Vxkp+7dFwSASTQGfZp1jcp5tGgAIQ3vA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6109 X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090207.4E7357E1.0191:SCFMA922111,ss=1,re=-4.000,fgs=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 141.146.126.227 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:82254 Archived-At: > if you're using eval on something you don't want eval'd > until the function is run, you should backquote it. > > (defun functionmaker (name form) > (eval `(defun ,name () ,form))) > > I used to associate backquoting exclusively with macros, but I think > that was wrong thinking. Right. But if you're evaluating the entire constructed form once at the top level like that, then you likely do want to use a macro. That's just what a Lisp macro is: a function that returns code that then gets evaluated. (defmacro functionmaker (name form) `(defun ,name () ,form)) Or, for the original question: (defmacro makeAbrevFun (name val) `(defun ,name () (insert ,val))) (makeAbrevFun aa "aaaaaaaaaaaaaa") Well, not quite - the OP quoted the function symbol, indicating that s?he would pass something that needs to be eval'd. If that's rally part of the requirement, then: (defmacro makeAbrevFun (name val) `(defun ,(eval name) () (insert ,val))) (makeAbrevFun 'aa "aaaaaaaaaaaaaa") In both cases: (symbol-function 'aa) gives: (lambda () (insert "aaaaaaaaaaaaaa"))