Re: [sv-bc] Mantis 1571: proposal for macro defaults

From: Greg Jaxon <Greg.Jaxon_at_.....>
Date: Wed Aug 15 2007 - 09:05:25 PDT
Bresticker, Shalom wrote:
> Hi, Dave. 
>
>> [What] happens if an argument to the macro is 
>> itself a macro that turns into empty text. Does the default apply?

Although it seems like having your cake and eating it too, I think
the answer here is effectively "yes".  A macro's arguments must be
fully expanded before they are substituted for their formal counterparts.
Macro expansion results in source text; the grammatical effects of
that text must not depend upon how it was provided or produced.  So
the outer macro must be unable to distinguish an empty text argument
that was merely omitted from one which is empty due to other macro
expansion or substitution actions.  For example,
`define N(form=123)
`define M(arg=) `N(arg)
allows `M() to expand to the text "123", even though N looks like it has
been given an actual argument.

>>
>> When is the default expression evaluated?

In Shalom's proposal, the default is raw text (constrained below*); it is
not an expression that needs evaluating.  However, as text, it could itself
be produced by a macro expansion.  There may be a little room for debate
about when to expand macros in the default text, but I think the precedents
here all favor expansion in the context of the macro's call site /before/
the expansion of the macro call itself begins.  For example, `Q1(2) and `Q2(2)
produce the same source text when defined as follows:

`define DBL(arg=form) ((arg) + (arg))
`define Q1(form) `DBL()
`define Q2(form) `DBL(form)

Macro expansion is famously dangerous and powerful because its formal/actual
substitution rule uses pure text substitution where macro and argument names
are resolved /at the call site/.
Attempts to make this less chaotic would be in vain.  The attempt
would also be unwelcome among the true believers in the brute force of
macro substitution.

[*] Important rule to add to proposal:
The text for a default macro argument is subject to the same constraints
as any actual argument in a macro expansion - i.e. it cannot have a "," or
")" character outside of balanced parentheses, balanced quotes, or escaped
identifiers.

Greg Jaxon


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Wed Aug 15 09:05:50 2007

This archive was generated by hypermail 2.1.8 : Wed Aug 15 2007 - 09:06:22 PDT