J3/06-343r2 Date: 2006/11/16 To: J3 From: Malcolm Cohen Subject: Notes on Clause 3 References: 06-210r2, 06-007r1 This is a response to 06-343. Q. [34:26-27] C313 needs to be rewritten so that it does not have three negatives. A. Agreed. EDIT. [34:26-27] Replace C313 with "If the first token is MACRO the second token shall not be a keyword or name." Q. Can the first be DEFINE or EXPAND? A. Yes. Q. If yes, then why are these separate items in the BNF for R322? The way things are it is ambiguous whether a statement DEFINE MACRO ... is a or a . A. This should be fixed. EDIT. [34:37+] Add new constraint "C3xx (R333) If the first token is DEFINE the second token shall not be MACRO." Q. As a specific example, can a macro define a macro with a variable number of arguments, where the number of arguments is an argument of the top-level macro? A. I do not understand this ambiguous question. Q. There is a clear provision for macros defining macros. Here is an attempt at an example of using such a macro---to be included in a Note or Annex C: A. Agreed. EDIT. Append example to clause 3. ! Macro that defines a macro which assigns a value to an array element DEFINE MACRO :: assign_shortcut(rank) DEFINE MACRO assign_%%rank(array,indices,value) MACRO INTEGER :: i array(indices(1)&& MACRO DO i=2,rank ,indices(i)&& MACRO END DO )=value END MACRO assign_%%rank END MACRO assign_shortcut ! Create assignment macros for all ranks MACRO DO i=1,15 EXPAND assign_shortcut(i) MACRO END DO ! Now use the rank-3 assignment macro: REAL :: A(10,10,10) INTEGER :: indices(3)=[1,5,6] EXPAND assign_3(A,indices,5.0) ! Expands to: ! A(indices(1),indices(2),indices(3))=5.0 Q. [36:30] I find "statement-dependent" in item (3) too vague---maybe say "Macro statement processing". The expansion of macros is in a sense iterative, expanding MACRO and EXPAND statements until there are none left to expand. This was not really clear to me from reading the description. A. The statement-dependent processing is specified immediately after the specification of token replacement and token concatenation (items 1 and 2). Q. [38:5-6] I believe that we should be specific that token replacement and concatenation are the ONLY forms of expansion that occur. A. We are specific in that we only define what happens. ===END===