[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: start-picture/get-picture question
- To: Rob Browning <firstname.lastname@example.org>, info-mcl
- Subject: Re: start-picture/get-picture question
- From: email@example.com (Steve Strassmann)
- Date: Tue, 25 Jan 1994 19:35:11 -0500
>Here is the function I defined to add graphic items to the window
>(more or less):
>(defmacro append-to-auto-redraw-window (win &rest items)
> `(with-focused-view ,win
> (start-picture ,win)
> (if (contents ,win) (draw-picture ,win (contents ,win)))
> (if (contents ,win) (kill-picture (contents ,win)))
> (setf (contents ,win) (get-picture ,win))))
In addition to the other good reponses, I'd like to take the opportunity
to talk about one of my favorite style tips... avoid macro abuse.
It's very common for beginners to go nuts with macros as soon as
they discover them, but 90% of the time, you really don't need them.
The moral of the story is: See if you can rewrite your code to use
functions instead of macros whereever you use them.
Don't use macros just because you're too lazy to use quotes.
If you want to do something to the symbol X, you can choose
if frobulate is a macro: (frobulate x)
if frobulate is a function: (frobulate 'x)
but ask yourself, do I really need the symbol X, or do I really
want to frobulate the *value* of X? Maybe your code is depending
too heavily on global variables, which is bad. Think about
a function like sqrt - it shouldn't need to know the variable
name of its argument, it should just operate on the value.
Don't use macros just because you want your code inlined.
C programmers use macros to get inlining, but in lisp, you can
simply tell the compiler to inline with declarations like
(proclaim '(inline frobulate)) [see Steele's CLtL2, page 222].
You'll find that using functions makes debugging a little easier,
and unlike macros, you can pass them around just like data
to other functions like mapcar.