From: Anselm Helbig <anselm.helbig+news2009@googlemail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: extracting serial repeats
Date: Sat, 23 Jan 2010 21:00:43 +0100 [thread overview]
Message-ID: <873a1w382c.wl%anselm.helbig+news2009@googlemail.com> (raw)
In-Reply-To: <mailman.74.1264262438.14305.help-gnu-emacs@gnu.org>
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
next parent reply other threads:[~2010-01-23 20:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.74.1264262438.14305.help-gnu-emacs@gnu.org>
2010-01-23 20:00 ` Anselm Helbig [this message]
2010-01-24 9:14 ` extracting serial repeats Andreas Röhler
[not found] ` <mailman.95.1264324380.14305.help-gnu-emacs@gnu.org>
2010-01-24 10:17 ` Anselm Helbig
2010-01-24 11:42 ` Andreas Röhler
2010-01-23 16:01 Andreas Roehler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=873a1w382c.wl%anselm.helbig+news2009@googlemail.com \
--to=anselm.helbig+news2009@googlemail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.