From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Anselm Helbig Newsgroups: gmane.emacs.help Subject: Re: extracting serial repeats Date: Sat, 23 Jan 2010 21:00:43 +0100 Organization: Freie Universitaet Berlin Message-ID: <873a1w382c.wl%anselm.helbig+news2009@googlemail.com> References: NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1264279345 351 80.91.229.12 (23 Jan 2010 20:42:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Jan 2010 20:42:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 23 21:42:18 2010 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 1NYmo5-0005pX-FQ for geh-help-gnu-emacs@m.gmane.org; Sat, 23 Jan 2010 21:42:09 +0100 Original-Received: from localhost ([127.0.0.1]:42045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NYmo6-0005sy-J9 for geh-help-gnu-emacs@m.gmane.org; Sat, 23 Jan 2010 15:42:10 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 61 Original-X-Trace: news.uni-berlin.de 87ocxfobolaJnzTseXTjlwQMMDfojRzkNcm7rAJ5oSLAJDnyoaOUxufowA Cancel-Lock: sha1:fJY4NbFF5656yXusfpswNFDUg24= In-Reply-To: Mail-Followup-To: Anselm Helbig Original-Xref: news.stanford.edu gnu.emacs.help:176336 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:71407 Archived-At: Hello Andreas! At Sat, 23 Jan 2010 17:01:40 +0100, Andreas Roehler wrote: > > Hi, > > let's consider the following pseudo-code, assumed inefficient, because Functions 1..n are identic. > > Function-1 > (Body-of-Function-1) > Follow-action-1 with Function-1 > Follow-action-2 with Function-1 > > Function-2 > (Body-of-Function-2) > Follow-action-1 with Function-2 > Follow-action-2 with Function-2 > ... > Function-n > (Body-of-Function-n) > Follow-action-1 with Function-n > Follow-action-2 with Function-n > > More efficient seems, having > > Body-of-Functions > > extracted into a subroutine > > so we could write something like > > (dolist (element (1..n)) > SUBROUTINE element > Follow-action-1 with element > Follow-action-2 with element > > Question is: exists a known tool for the extraction resp. refactoring needed? Sounds like a case for a macro: (defun foo-function (i) `(defun ,(intern (format "foo-function-%d" i)) (arg1 arg2) (message "this is the body of the function"))) (defmacro define-foo-functions (n) `(progn ,@(loop for i from 1 to n collect (foo-function i)))) The question is, however, why do you need functions with a number in their name, shouldn't this be an argument to the function? HTH, Anselm -- Anselm Helbig mailto:anselm.helbig+news2009@googlemail.com