The above example illustrates that the order in which Ferret performs string substitutions and evaluates immediate mode expressions in the command line is significant. The successful evaluation of the embedded expression `($ppl$xlen)/2` requires that ($ppl$xlen) is evaluated before attempting the divide by 2 operation. The order of Ferret string substitutions is as follows:
1. substitute "GO" command arguments of the form "$1", "$2", ...
2. substitute symbols of the form ($symbol_name) (discussed here)
3. substitute command aliases
4. substitute immediate mode expressions. (But see example 3 below).
Example 1
If the script snoopy.jnl contains
DEFINE SYMBOL fcn = $1
DEFINE ALIAS ANSWER LIST/NOHEAD/FORMAT=("Result is ",$2)
ANSWER `($fcn)(($3^2)/2)`+5
then the command
yes? GO snoopy EXP F5.2 2.25
would evaluate to
DEFINE SYMBOL fcn = EXP
DEFINE ALIAS ANSWER LIST/NOHEAD/FORMAT=("Result is ",F5.2)
LIST/NOHEAD/FORMAT=("Result is ",F5.2) `EXP((2.25^2)/2)`+5
and would result in Ferret output of "Result is 17.57."
Example 2
We can use grave accent syntax and string variables to substitute the string into the command line.
yes? LET my_reg = "X=0:180,Y=-40:40,L=1"
yes? SHADE sst[`my_reg`]
Example 3
Immediate mode substitution of a string variable may be used to set the values of qualifiers. However the region qualifiers (/X=/Y=etc.) on a command are used to set the context for the grave accent expression. So Ferret parses command qualifiers before it parses grave accent expressions. Thus we can use this syntax to set a region:
yes? LET xreg = "40:180"
yes? LET yreg = "60S:42S"
yes? SET REGION/X=`xreg`/Y=`yreg`
But including the qualifier name in the string variable is NOT valid (the qualifier is parsed BEFORE the grave accent expression is substituted, so Ferret would issue the error that `my_region` is an unknown qualifier).
yes? !The following syntax is NOT valid:
yes? LET my_region = "x=40:180/y=-60:-42"; set region/`my_region`
yes? ! THE FOLLOWING syntax IS valid:
yes? DEFINE SYMBOL my_region = X=40:180/Y=-60:-42
yes? SET REGION/($my_region)
!-> SET REGION/X=40:180/y=-60:-42