Editor support for refactoring with macros?



Suppose I have a bunch of code with obviously redundant patterns in it.
So I define an obvious simple macro to factor out some of the
redundancy. Shouldn't a smart editor that understands lisp be able to
automatically convert my redundant code to use the new macro?

Here's an example taken from my (possibly silly) attempt to replace
Microsoft Money with some simple lisp:

A typical purchase from my main checking account might look like this:

(purchk 20060101 880 "QFC"
:tax-sales 244
:household (- 880 244) "Batteries")

20060101 is a date, for which I'll worry about finding a better
representation later.

880 is the total amount of the transaction charged to checking. I'm
entering money amounts in integer pennies for now. I may look for a
fixed-decimal representation someday.

QFC is the payee, the chain where I do most of my grocery shopping.

It says I paid $2.44 in sales tax, which seems unreasonably high, and
the rest for batteries, charged as household expense. As I recall
there was a storm and power failure last January 1st.

I had most of a year's worth of transactions entered in that style,
when I finally decided to factor out some of the repetition:

(defmacro qfc (date total &body body)
`(purchk ,date ,total "QFC"
,@body))

So that example transaction would refactor as:

(qfc 20060101 880
:tax-sales 244
:household (- 880 244) "Batteries")

Ok. Very simple. Baby stuff.

But now I've been converting my old code and keep thinking a lisp
function ought to be able to accept my macro definition and my existing
code, and spit out my code automatically converted to use the macro
where appropriate.

Surely I'm not the first person to think of this. Do the commercial
lisp implementations have this already? How hard would it be to code
it up in elisp+slime?

.



Relevant Pages

  • Re: Editor support for refactoring with macros?
    ... So I define an obvious simple macro to factor out some of the ... redundancy. ... Shouldn't a smart editor that understands lisp be able to ... 880 is the total amount of the transaction charged to checking. ...
    (comp.lang.lisp)
  • [OT] PostLisp, a language experiment
    ... IMHO the worst thing in Lisp is its many parentheses. ... The worst thing about Forth IMHO is the stack clutter. ... And while I could write a macro like (with bla ... The ret is the explicit return continuation. ...
    (comp.lang.lisp)
  • Re: Program compression
    ... problems to be solved much more concisely than with Lisp. ... In Common Lisp, it's another one line of code: ... My point is that different languages are based on different things ... it would be impossible for the author of a macro (in the Lisp ...
    (comp.programming)
  • Re: Why is LISP syntax superior?
    ... that lisp was the most powerful programming language ever invented, ... It is precisely the lack of syntax that I admire in Lisp ... (setf (elt seq i) ... I guess one could write a reader macro to transform foointo (elt ...
    (comp.lang.lisp)
  • Re: Python gets macros - now XML does too
    ... > I think the main advantage: You use Lisp within a Lisp macro to generate ... > generation part in another language than the description to generate the ... MetaL compiler flow module provides support for level 0 (macro ... Despite currently I only use PHP because I only develop Web ...
    (comp.lang.lisp)