(j3.2006) Macro questions

Malcolm Cohen malcolm
Tue Jan 30 23:03:27 EST 2007


Hi folks,

Well, my time is limited, but anyway...

...I'll answer one question for now (why do people have to ask so
many questions at once?).

> 3. In the example in point 2 above, I could not write:
> INTEGER(KIND=kind), INTENT(IN) :: X
> because both appearances of the token KIND would have been replaced
> by the integer value of the macro variable kind. Correct?

Yes.

> This seems to me to be inconsistent with the rest of Fortran and
> also rather inconvenient for programmers.

I don't find it inconsistent myself, but ok.

> However, I don't see an easy fix...

Surely the easy fix is Just Don't Do That!

The "KIND=" is optional anyway.

You're not *required* to call the macro dummy argument KIND.

If you want to call the macro dummy argument KIND, *and* want to have
"KIND=" in the macro expansion, use a helper macro (ok, so this
irritatingly multiplies the number of macros needed and visible, but
it does the job).  For example (different from yours, but I deleted
it from the editor buffer already):

  DEFINE MACRO declare(name,kind)
    EXPAND declare_helper(name,kind)
  END MACRO
  DEFINE MACRO declare_helper(n,k)
    INTEGER(KIND=k) n
  END MACRO

then

  EXPAND MACRO declare(x,KIND=3)

expands to

  INTEGER(KIND=3) x

So much for the workarounds.
The "easy fix" for the feature is to have $quote, e.g.
  INTEGER($quote KIND = kind) name
where $quote protects the next token against expansion,
i.e. it quotes it.

However, although $quote is cute and occasionally useful,
it's not so essential that I think it needs to be included right now.
Many other macro processors don't have it.

As for "not so easy" fixes, I must admit I cannot think of one
off-hand...  oh yes I can, we could make macro variable names
case-sensitive (recoil in horror!).

Cheers,
-- 
........................Malcolm Cohen (malcolm at nag-j.co.jp), Nihon NAG, Tokyo.



More information about the J3 mailing list