Home | Web Design | Programming | Fairlight CMI | Soap Box | Downloads | Links | Biography | About... | Site Map |
The Macro Operator "&" |
CA-Clipper | Opportunities | Tips and Tricks | Networking | Internal Errors | Source Code | CA-VO |
BACK TO CA-CLIPPER TIPS & TRICKS |
The macro operator has been around for quite a few versions of CA-Clipper.
In fact it was also available in dBase. It has been used for some fairly
obscure (read: bad) source code tricks. But then, in the "good old days"
there were fewer alternatives! For the most part, the macro operator has been replaced by code blocks (see The Evolution of Code Blocks). Nevertheless, it is useful to understand the macro compiler, if only to understand the "legacy" code that has to be maintained. Jumping right in, consider the following source code:
X is assigned the number 10, while the variable
Y is assigned the character string 'X' , which is
the name of the first variable. Line 3 shows the macro operator at work. The ampersand ( & ) and
the period surround the variable Y like a pair of parentheses.
This line of code causes the number 10 to appear on the screen. Looking closer at this, you can see that the variable X
contains the number 10, so why does line 3 of the sample print 10?
Using a high school mathematics technique, substitution, some
light can be shone on this. On line 2, Y is defined as 'X' , so substituting
this into line 3 gives:03 ? &'X'. Now, use the ampersand and the period to "cancel out" the quotes: 03 ? --X-- Which leaves this: 03 ? X This line prints the value of X , which is 10. Note The CA-Clipper documentation indicates that the period is optional when used with the macro operator, but I like to include it because of the way that it reminds me to "cancel the quotes". Here is another example:
03 ? &'X + 1'. The macro operator and period cancel the quotes: 03 ? --X + 1-- Which leaves this code: 03 ? X + 1 Another example:
The macro operator has a few limitations, such as the fact that variables referenced inside the string ( X in the samples above) cannot
be local variables. Also, functions used in the macro string
(abs() in the sample) must be explicitly linked into the
program (usually by simply including external ABS at the top
of the source code file. Nevertheless, the macro operator is still used occasionally, although it has been mostly superceded by code blocks. |
Home | Web Design | Programming | Fairlight CMI | Soap Box | Downloads | Links | Biography | About... | Site Map |
Send comments about this site to Greg at
gregh@ghservices.com All pages copyright © 1996-1999 GH Services Created 1997/06/06 Last updated 1999/09/30 All trademarks contained herein are the property of their respective owners |