A quirk in macro parsing

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

A quirk in macro parsing

Richard Ristow
The following apparent quirk in macro parsing drove me batty. The
listing that follows is SPSS 15 draft output.

* If !A is a macro that expands into "'Alpha'" (with the quotes), then
ECHO 'Letter is ' + !A .
seems to be parsed with the macro expanded, to get
ECHO 'Letter is ' + 'Alpha .
and prints "Letter is Alpha".

* If !B is a macro variable whose value is "'Beta'", then
ECHO 'Letter is ' + !B .
seems to be parsed with the variable value NOT substituted for, giving
>Warning # 207 in column 6.  Text: Letter is
>A '+' was found following a text string, indicating continuation, but
>the next non-blank character was not a quotation mark or an apostrophe.

The resulting generated string has the expansion, but the "+"
catenation doesn't work:
   27 M>  ECHO 'Letter is ' 'Beta'

I guess I expected that not just all macros, but all macro variables,
were substituted before an SPSS command was parsed at all. Doesn't seem
to be quite true, for macro variables.
=====================
Demonstration listing
=====================

DEFINE !A() 'Alpha' !ENDDEFINE.

ECHO 'Letter is ' + !A .
Letter is Alpha

DEFINE !Write_B ()
    !LET !B = 'Beta'.
    !LET !B = !QUOTE(!B).
ECHO 'Letter is ' + !B .

 >Warning # 207 in column 6.  Text: Letter is
 >A '+' was found following a text string, indicating continuation, but
the
 >next non-blank character was not a quotation mark or an apostrophe.

!ENDDEFINE.

PRESERVE.
SET MPRINT ON.
!Write_B.
   24 M>
   25 M>  .
   26 M>
   27 M>  ECHO 'Letter is ' 'Beta'
Letter is
   28 M>  .
RESTORE.
   29 M>  RESTORE.