Editor support for refactoring with macros?
- From: "phr" <philrand@xxxxxxxxx>
- Date: 25 Dec 2006 17:02:26 -0800
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?
.
- Follow-Ups:
- Re: Editor support for refactoring with macros?
- From: Pascal Bourguignon
- Re: Editor support for refactoring with macros?
- Prev by Date: CLISP socket binding loopy?
- Next by Date: Re: CLISP socket binding loopy?
- Previous by thread: CLISP socket binding loopy?
- Next by thread: Re: Editor support for refactoring with macros?
- Index(es):
Relevant Pages
|
|