[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
macros vs inline question
- To: D1104@AppleLink.Apple.COM (Computer SW Consult, J Stulin,PAS)
- Subject: macros vs inline question
- From: Steve Strassmann <straz@cambridge.apple.com>
- Date: Wed, 22 Apr 1992 17:15:30 -0500
- Cc: info-mcl
>Date: 16 Apr 92 01:33 GMT
>From: D1104@AppleLink.Apple.COM (Computer SW Consult, J Stulin,PAS)
>Subject: macros vs inline question
>To: INFO-MCL@CAMBRIDGE.APPLE.COM
>
>Dear Friends:
>
>
>In a current project I have been using Macros extensively to avoid function
>calling overhead. I am aware that Common Lisp supplies an INLINE facility which
>may be preferable to using Macros. I have two questions.
>
>First, under what circumstances (if any) does MCL satisfy the INLINE request.
2.0b1 didn't, but more recent versions of MCL (including the final) will
always honor INLINE. You have to proclaim it before you define the function,
or declare it inside the function.
>Second, is the primary proper use of Macros to create new syntactical
>structures?
In general, yes. It's also handy for making sure that multiple things get done
in a clean, consistent way. For example, one macro invocation can create
several related definitions (such as matched setter/getter functions).
Many macros beginning with "WITH-", such as WITH-OPEN-FILE, are used to
guarantee that a form is executed in a proper context, and the appropriate
cleanup actions are always performed in an unwind-protect in case of interruption.
Using macros just to speed up your code is not necessarily a good idea, since
INLINE is usually better. Also, using macros to save yourself typing
the occasional quote char is sometimes handy, but you should usually provide
a function to do the same task, and have the macro expand into that function.
Reason #1 is that macros can't be passed to MAP and APPLY the way functions can.
Reason #2 is that although the feature of not EVALing their arguments looks like
a boon to top-level evaluation, it becomes a pain when you want to call macros
as subroutines from within other functions.