From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joost Diepenmaat Newsgroups: gmane.emacs.help Subject: Re: Programmatically creating functions Date: Tue, 21 Oct 2008 20:34:07 +0200 Organization: Zeekat Softwareonwikkeling Message-ID: <87r669lrvk.fsf@zeekat.nl> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1224614586 3617 80.91.229.12 (21 Oct 2008 18:43:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 Oct 2008 18:43:06 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 21 20:44:03 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KsMCh-0007zw-A6 for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Oct 2008 20:43:39 +0200 Original-Received: from localhost ([127.0.0.1]:55399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KsMBb-0007Gn-VE for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Oct 2008 14:42:31 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Face: iVBORw0KGgoAAAANSUhEUgAAABgAAAAwBAMAAAD5pqeQAAAAAXNSR0IArs4c6QAAABhQTFRF URgKoyIAmTMXqF5KuYl7y6ui4NDM+/r4zJNdmwAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsT AQCanBgAAAAHdElNRQfXDBIUAgGiEa2aAAABYUlEQVQoz02SvXaDMAyF3aHdZegD2PxkJhQ8J4R6 juGUuZDUe43R61eGJA0D8B1dXV0LGCJaDDePyOjZBtT9MgSYbIu+UpNl2A+/ukPXfNUku2ROdWhM 99myqzWX3Czp8dhY1n+MfWau+X4fZGNZpecuSwpFMHOZnpskFppgEaksGs5lFoYeYilOEMkjzcGC CzjxJJoowZIAQMPhfdYEecGhBFCOwO9GKkFkXZDtfIAax2C9wwKAWzwFyPGwQrXCIkimbzAHeFtl Ts0vJHvFkRI01ssVwpyMAoHkGmfFqL+TEmSNXjHMXeiHZAjZqjOsVxxSV8UG3Fi2ZGID2Fs2t7d3 6mLTdIdUM+PuECvW/T6gfobnSqTY+DDgmrnmATSnfMiQrTvcDOikyT1OWHxZPIF8As8P/waOjzdn IGt+vRVgYD7CrakFTSfFbwAB0Y+ghWj0IjP0Scz6I2E3zIlFb/8AfR6DwKVgwNYAAAAASUVORK5C YII= Cancel-Lock: sha1:tN7bVgnxkwiYH2Hf+AhzL1ynews= Original-Lines: 41 Original-NNTP-Posting-Host: 80.126.3.69 Original-X-Trace: 1224614101 news.xs4all.nl 198 [::ffff:80.126.3.69]:47628 Original-X-Complaints-To: abuse@xs4all.nl Original-Xref: news.stanford.edu gnu.emacs.help:163657 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58997 Archived-At: Ian Eure writes: > So, I have a list of symbols: > > '(foo bar baz) > > I want to iterate over the list and create a function from each which > does something like this: > > (defun call-foo () > (interactive) > (invoke-stuff 'foo) > > How can I accomplish this? I can't figure out how to create the > function. I've tried a number of approaches, but have not met with > success. > > - eval'ing the defun. Returns a function symbol, but I can't call > it. Maybe it's only created within the scope of the (eval) and not > callable from outside? > > - Creating a symbol and using fset to assign a lambda to it's > function cell. It sort of works, but I'm unclear on how to pass a > variable function name to defun, nor am I clear on how I can make sure > it calls invoke-stuff with the right symbol. I'm not /quite/ sure where you've got problems, but in this case elisp's lack of closures hurts. IMHO the simplest way to get what you want is to use a macro: (defmacro make-caller-macro (symbol) `(defun ,(intern (concat "call-" (symbol-name symbol))) () (,symbol))) But that won't evaluate the argument, so you'd more or less have to use eval as well: (dolist (s '(foo bar)) (eval `(make-caller-macro ,s))) -- Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/