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

Re: RE Parsing with XS



Reply to note from Patricia M Godfrey  Sat, 18
Oct 2003 17:30:07 -0400

Patricia:

> Some things cannot be just SaVed, they have to be Saved and
> eXamined

The operative word being "just". All strings can be SV'd. There's
a subset of strings that can also be "eXamined" (evaluated to a
result); only these can be SX'd. SV virtually always works; SX
sometimes bombs.

For example, "a+b" is a string, so  works. But "a+b"
doesn't evaluate, so  bombs (Error 488, "SX command
requires a number").

By contrast, "2+2" evaluates to "4", so that either  or
 is acceptable. The choice depends on your purpose.
Think of "2+2" as a problem that has an answer. If you want to
state the problem, use SV; if you want to report the answer, use SX.
In pseudo-code:

;*; Reports "2+2"
;*; Reports "4"

Here are some examples of strings and their evaluated results (if
any):

String (after SV)  Evaluation (after SX)
2+2         4
"2+2"        2+2
"2"+"2"       22
a+b         [bombs]
"a+b"        a+b
"a"+"b"       ab
XyWrite       [bombs]
"XyWrite"      XyWrite
"Xy"+"Write"     XyWrite
     October [current month]

VA's almost always have to be saved with SX (not SV), because
usually you want to report the evaluated result of the VA statement,
not the statement itself. But one could imagine exceptions.
Compare:

>;*;

with

>;*;

Note, in the table above, that a quoted string evaluates to the
string itself, and a concatenation, or two or more strings strung
together ("2"+"2"), evaluates to the strung-together string ("22").
The fact that one or more of the constituent strings happen to be
numbers is neither here nor there.

Also, compare "2+2" with "2"+"2". In the first, the plus sign is
part of the string in quotes, so that the result is the string
itself (2+2). In the second, the plus sign is not in quotes; it's
an XPL operator denoting string "addition" (concatenation). The
result is "22".

All diner waiters know this, at least in NYC. "Scramble twenty-two"
doesn't mean 22 eggs; it means 2 eggs (on separate plates) for 2
customers ordering together.

--
Carl Distefano
cld@xxxxxxxx
http://users.datarealm.com/xywwweb/