[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Counting Up in XPL



To Tim Baehr and All:

Tim, in your 11/4/95 post you refer to a CU command, yet another
undocumented XPL statement that appears in XY4.DLG. It takes the
form

«sx01,n»«culabel,01»[code]«lblabel»

At that time you said, "I don't know what the heck the CU label
does, precisely. But it looks like it repeats an operation N times, with ...
N being set in S/G [01]." I've done some testing and you're
right. What it does is to repeatedly execute whatever code appears between the
CU statement and the corresponding LaBel, where the number of
repetitions is determined by the S/G referenced in CU. In
essence, a specialized Go_Label command that "Counts Up" to the
specified number of reps.

This is handy. It's more compact that the usual
increment-test-loop back procedure. And since it's native XPL,
not a user construct, it's much faster. At least 6 times as
fast, according to my tests.

One caveat: The XPL interpreter expects to find a whole number
of reps, and it's somewhat erratic in its interpretation of
fractional numbers. If you say «sx01,9.5»«cua,01»[code]«lba»,
you get 95 repetitions, not 9 or 10 as you'd expect! However,
saving the fractional value as a string rather than an expression, as in
«sv01,9.5»«cua,01»[code]«lba», does yield 9 reps. This suggests
that, in practice, if there's any doubt whether the referenced
variable contain a whole number (e.g., if the value is handed
over by another routine or is taken from user input), it should
be converted to an integer with «sx01,@int(«pv01»)» before
executing CU. Actually, to be absolutely rigorous, you'd first
have to check whether the S/G contains a number at all, by
looking at «va01». If «va01» is 0 (i.e., the contents are a
string, not a number), it may be necessary to set a default
number of reps, unless no reps is acceptable. (If the reference
S/G contains an alpha string, CU does nothing. If a mixed
alpha-numerical string, it uses any leading numbers. Thus
«sv01,5a» yields 5 reps, whereas «sv01,a5» yields none. This
gives a clue as to why «sv01,9.5» is interpreted as 9.)

Many thanks for pointing out this useful command.

--------------
Carl Distefano
70154.3452@xxxxxxxx