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: Sun, 24 Jan 2010 11:17:07 +0100

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? 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, 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


-- 
Anselm Helbig 
mailto:anselm.helbig+news2009@googlemail.com


reply via email to

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