Progress
Programming
Handbook


Expanding Preprocessor Names

When Progress encounters a reference to a preprocessor name, Progress replaces the reference with the value of the preprocessor name’s definition. This is called expanding the reference:

&GLOBAL-DEFINE TABLE customer 
&GLOBAL-DEFINE FIELD cust-name 
&GLOBAL-DEFINE WHERE-CLAUSE WHERE {&FIELD} <> "Al’s Antiques" 
FIND NEXT {&TABLE} {&WHERE-CLAUSE}. 

The first reference in this example is {&FIELD}. The curly brace ( { ) and ampersand ( & ) direct Progress to expand the reference. By checking the definition of the preprocessor name FIELD, Progress determines that its value is cust–name. Progress therefore replaces the reference with cust–name. As a result, WHERE–CLAUSE is defined as follows:

WHERE cust-name <> "Al’s Antiques" 

The second reference is {&TABLE}. Progress replaces this reference with customer; customer is the definition of the preprocessor name TABLE.

The third reference is {&WHERE–CLAUSE}. Progress replaces WHERE–CLAUSE with its definition, which has already been expanded.

After Progress has made all of these evaluations, the preprocessing phase of compilation is complete. This is the FIND NEXT statement that Progress compiles:

FIND NEXT customer WHERE cust-name <> "Al’s Antiques". 

In the previous example, the reference {&FIELD} was evaluated first. Progress also allows you to defer the evaluation of a reference. By placing a tilde (~) in front of a preprocessor name reference, you indicate that you do not want to expand the reference when it is first encountered. (On UNIX, you can also use the backslash character ( \ ) to defer evaluation.):

&GLOBAL-DEFINE FORM-LIST cust-num ~ 
FORMAT >>>9 ~{&OTHER-FIELDS} WITH FRAME X 
&GLOBAL-DEFINE OTHER-FIELDS cust-name SKIP city state 
FIND FIRST customer. 
DISPLAY {&FORM-LIST}. 
&SCOPED-DEFINE OTHER-FIELDS phone. 
DISPLAY {&FORM-LIST}. 

Progress does not expand the reference {&OTHER–FIELDS} in the definition of FORM–LIST, because {&OTHER–FIELDS} has a tilde in front of it. In this instance, the curly brace has no significance to Progress because of the tilde.

This is how Progress defines FORM–LIST.

cust-num FORMAT >>>9 {&OTHER-FIELDS} WITH FRAME X  

Instead of trying to expand the reference {&OTHER–FIELDS}, Progress simply includes it in the definition of FORM–LIST.

When the preprocessor reaches the first DISPLAY statement, Progress expands the {&FORM–LIST} reference. Since the definition of FORM–LIST includes the {&OTHER–FIELDS} reference, Progress recursively expands {&OTHER–FIELDS}. As a result, Progress replaces {&FORM–LIST} with this.

cust-num FORMAT >>>9 cust-name SKIP city state WITH FRAME X 

The &SCOPED–DEFINE directive changes the value of OTHER–FIELDS. As a result, the second {&FORM–LIST} reference expands like this:

cust-num FORMAT >>>9 phone WITH FRAME X. 

When you defer the evaluation of a reference, make sure that the reference will have a value at the point of expansion. The following example does not do this:

p-proc.p
&GLOB file customer 
{p-incl.i} 
FOR EACH {&file}: 
  DISPLAY {&fields}. 
END. 

p-incl.i
&GLOB fields ~{&field_list} 
&SCOP field_list name max-credit 

In this example, the mistaken intention was to defer the evaluation of {&field_list} until {&fields} is expanded. However, since field_list is nonglobally defined, its value does not extend beyond the end of p-incl.i. As a result, there is no value assigned to field_list at the point of expansion of {&fields}.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095