[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: extracting serial repeats
From: |
Andreas Röhler |
Subject: |
Re: extracting serial repeats |
Date: |
Sun, 24 Jan 2010 10:14:03 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20081227) |
Anselm Helbig wrote:
> 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
>
>
>
Hi Anselm,
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.
Can do that by hand, sure. But as the issue shows up occasionaly, a tool
doing these extractions might be useful.
Andreas