help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: extracting serial repeats


From: Anselm Helbig
Subject: Re: extracting serial repeats
Date: Sat, 23 Jan 2010 21:00:43 +0100

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]