4.4 Mixed-case Strings and Embedded Blanks

Upper and Lower Case

Aspen SCM Expert System remains a predominantly upper-case system. To use lower-case at all you must have switch 5 set to Yes on the Options/Control menu. You can force this by including the command SWITCH 5 = YES in $LOAD.

Single and Double Quotes

Within Aspen SCM Expert System code, double quotes are used to define literal text strings, e.g.

IF      ?MESSAGE = "Hello world"

Single quotes are used to allow the values of rule variables to be substituted into strings, e.g.

IF      ?MESSAGE = 'Hello ?CALLER'
        . . .
THEN    RESPOND_TO ?CALLER

They also coerce a variable to character string data type, so the statement ?A = '?B' will never be interpreted as a test whereas ?A = ?B may be.

You can get a single quote into a variable by double-quoting it:

IF      ?SQUOTE = "'"

It is more difficult to get a double quote into a variable. The best way seems to be to define a set, e.g. QUOTE, with an element DOUBLE whose Description consists of a single double quote. Then the statement:
IF      ?DQUOTE = QUOTE(DOUBLE,D)

achieves the task.

Leading and Trailing Blanks

Trailing blanks are always stripped from strings: quotes ensure that leading and embedded blanks are preserved but can do nothing for trailing blanks. For this reason it is often better to manipulate strings from right to left rather than left to right: that way any blanks will be significant.

The presence of leading and embedded blanks in local and global variables is supported fully by the Aspen SCM Expert System. In particular, the argument-passing mechanism for predicates regards each local or global variable as a single item irrespective of the number of tokens it may contain.

Enclose Literal Character Strings in Quotes

Although it is supposedly not strictly necessary to enclose character strings in quotes, you are strongly recommended to do so. Thus

IF      ?ACTION = "R"

is to be preferred to

IF      ?ACTION = R

If a character string contains embedded blanks the interpreter will not recognise this and will instead regard the statement as a predicate (see section 2.a).  Thus

IF      ?MESSAGE = Hello world

is regarded as asserting a predicate with 4 tokens. If there isn't one which matches this, the interpreter will try all predicates with 4 tokens one after another in a futile attempt to prove the assertion.

Even if your string forms a single token, there is still the possibility of impenetrable errors if the string is capable of being confused for an Aspen SCM keyword or a predicate verb. Such errors involve overwriting of areas of the interpreter’s memory and manifest themselves in unconnected statements, usually in different rules, making it very difficult to track down the cause of the problem. (The ?ACTION = R statement caused the interpreter not to execute a statement in an unrelated routine although ETRACE indicated that it had been executed.)


Back                                Next
Comments