From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: extracting serial repeats Date: Sun, 24 Jan 2010 12:42:11 +0100 Message-ID: <4B5C3213.6050807@easy-emacs.de> References: <873a1w382c.wl%anselm.helbig+news2009@googlemail.com> <87wrz724f0.wl%anselm.helbig+news2009@googlemail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1264333298 20853 80.91.229.12 (24 Jan 2010 11:41:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 24 Jan 2010 11:41:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 24 12:41:31 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 1NZ0qP-0005hF-Bs for geh-help-gnu-emacs@m.gmane.org; Sun, 24 Jan 2010 12:41:29 +0100 Original-Received: from localhost ([127.0.0.1]:54304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZ0qQ-0007ms-EC for geh-help-gnu-emacs@m.gmane.org; Sun, 24 Jan 2010 06:41:30 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZ0q2-0007mO-EO for help-gnu-emacs@gnu.org; Sun, 24 Jan 2010 06:41:06 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZ0pw-0007jU-Pm for help-gnu-emacs@gnu.org; Sun, 24 Jan 2010 06:41:05 -0500 Original-Received: from [199.232.76.173] (port=43791 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZ0pw-0007jR-JK for help-gnu-emacs@gnu.org; Sun, 24 Jan 2010 06:41:00 -0500 Original-Received: from moutng.kundenserver.de ([212.227.126.186]:57012) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NZ0pw-0000dw-56 for help-gnu-emacs@gnu.org; Sun, 24 Jan 2010 06:41:00 -0500 Original-Received: from [192.168.178.27] (p54BEB76F.dip0.t-ipconnect.de [84.190.183.111]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0LuHH1-1NzJQj2TAN-011Y2T; Sun, 24 Jan 2010 12:40:59 +0100 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: <87wrz724f0.wl%anselm.helbig+news2009@googlemail.com> X-Provags-ID: V01U2FsdGVkX1/mpMc7PggjXx2dxC3ou90mgEiKaMieHB+g2dd wRGHahK1chTDgHn4W9FqYfTBSgGQnJ35plIWKuiV3yh/9B0dYI PslvJTqtq+fM9zIoIW7u7dLs2mfz8dlsAovsozsWbY= X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:71416 Archived-At: Anselm Helbig wrote: > Hi Andreas! > > >> thanks a lot. >> >> Seems I didn't describe the problem well: it's something like: "How to >> avoid parallel implementing?". >> Or let's say it that way: >> >> Given a serial or serials of lambda-forms which take arguments of the >> same kind processing it the same way, >> but differ in function-names, they are referring to. >> >> Instead of implementing the same forms repeatedly under different names, >> we could re-use one. >> > > So you don't like the macro approach because it's still creating a lot > of functions internally? If you'd like to share the implementation, > the code could look like this: > > (defun foo (n a b c) > (message "n: %d; a: %s; b: %s; c: %s" n a b c)) > > (defun make-foo-function (n) > (lexical-let ((lexical-n n)) > (lambda (a b c) > (foo lexical-n a b c)))) > > (dotimes (i 22) > (fset (intern (format "foo-function-%d" i)) > (make-foo-function i))) > > (foo-function-21 1 2 3) > > I there's anything unclear about this code or the defmacro-approach I > gave you before, just ask. > > >> Can do that by hand, sure. But as the issue shows up occasionaly, a tool >> doing these extractions might be useful. >> > > Maybe I didn't get the issue right: you've got repetetive code to > start with and want to have it refactored automatically? yes > It's > certainly possible to have such functionality, on the other hand, you > don't have to write repetetive code in lisp in the first place, yes, rather avoid it. The scenario is: it just happened. Precisely while writing some tests. Wrote one form testing a patch, another form testing another patch, then remarked the parallels... Thanks again Andreas > that's > what macros are for. And, as shown above, you can also use functional > programming techniques to the same end. > > All the best, > > Anselm > > >