[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using Macros in Lisp



Reply to: lynch@aristotle.ils.nwu.edu (Richard Lynch)

	A:  You have to. (e.g. a class assignment)

What does this mean?

	B:  It will be used in LOTS of places in your code and will save you LOTS
	of typing and make the code a LOT clearer.  (e.g. (with-open-file..))

WITH-OPEN-FILE exists for a different reason, but I get your point.  However,
if you going to use an experssion in LOTS of places, if it expands into
a non-trivial form, it sounds like the code it expands into will take up
LOTS of space.  This might be a reasonable trade-off, but one needs to be aware
of it.  If the form is not time-critical, then you'll be avoiding negligible 
overhead by not making it a function, and making your lisp unnecessarily "bigger".

	C:  You NEED the arguments to be unevaluated so you can process them BEFORE
	    you do the function.

		(e.g.  (defmacro frame (name) `(find-frame ',name)))

I don't understand the usefulness of this form... could you elaborate?

	D:  You are going to save a LOT of run-time cycles by computing something.
	(e.g.  (defmacro slot-value (type object slot-name)
	           ;...hairy computation of integer result deleted...
	          `(svref (node-vector ,object) ,result)))

There are better ways to do this... in fact I would seriously disagree
with the integrity of this example.  Its very important to be careful
about bookeeping at compile-time.  You can get yourself into alot of 
trouble, especially if you keep the compile-time information around
in the environment after load.  Altogether, I think you could do
just as well without macros.  Can you think of another example besides
reimplementing defstruct?  Perhaps, then, I can be more concrete.

	E:  You need to be able to setf some portion of a structure.
	(e.g. (setf (slot-value person *fred* name) "Fred"))

Maybe clarifying D will suffice.  But I don't know what you mean here.

-david