Symbols

Symbols are GQEs that consist of a name and a value. They can be used as variables or as shorthands for commands. The value of a symbol is always a character string which is interpreted as text or a number depending on the subroutine which actually uses the symbol.

A "=" which appears as the second token of a command string identifies a command as a symbol assignment (the definition of the term "token" is given in section 5.2). The first token is the symbol name and the rest of the line behind the "=" is the value:

SPECTRA> symbol = value
Symbol names must not begin with a digit.

Symbols, which are created this way, are stored in descending order beginning in the last slot. If a symbol has to appear in a particular slot, the symbol() function has to be used (sect. 14.5.17):

SPECTRA> symbol( id, symbol) = value
ID identifies the slot where the symbol goes.

Before a symbol is inserted into the queue, SPECTRA checks whether the symbol name matches one of the keywords. If it finds a match, a warning message is displayed. Users who want to avoid the re-definition of keywords enter the command:

SPECTRA> set noredefine
The command
SPECTRA> set redefine
restores the default status.

Symbol values can be read from the terminal:

SPECTRA> inquire symbol prompt_string
SPECTRA displays the prompt_string and waits for the user to enter the symbol value. It is also possible to read a single character from the terminal and store it in a symbol:
SPECTRA> inquire/keyw symbol prompt_string
SPECTRA> inquire/key symbol prompt_string
The /keyw qualifier lets SPECTRA wait for the keystroke. If the /key qualifier is supplied, the program just reads the input buffer and carries on with the execution of the next statement.

Symbols are deleted by omitting the value:

SPECTRA> symbol =

If the value string contains significant blanks, it has to be enclosed in double quotation marks (Gänsefüßchen):

SPECTRA> s1 = "dies ist ein test"
If there were no quotation marks, S1 would have the value "diesisteintest".

Symbols can be protected against further interpretation by putting them into square brackets:

SPECTRA> s1 = [Energy [keV]]
Consider an additional unprotected symbol like:
SPECTRA> txt = " set /text="
The command:
SPECTRA> txt s1
translates the symbols and splits TXT into the verb SET and the first part of a qualifier assignment /TEXT=. The value of S1 "Energy [keV]" is kept as one token. The inner square brackets are not removed.

It is also possible to create protected symbols with an inquire command:

SPECTRA> inquire/protect sym_name ...

Symbol translation occurs in several places:

  1. When the interpreter is called, SPECTRA tries to translate the whole command string as a symbol.
  2. When the command line is cut into pieces, called tokens, SPECTRA tries to translate them. This happens before the tokens are identified as a verb, a parameter or a qualifier.
  3. Before parameters and qualifiers are used, they are evaluated as text strings or numbers. This step includes symbol translations.
  4. There is a function translate() (sec. 14.5.20) which explicitly translates a symbol.

The following command line shows how symbols are concatenated:

SPECTRA> sym1 = sym2"text1"sym3"text2"...
The text between the symbols can be omitted. e.g.:
SPECTRA> s1 = guten
SPECTRA> s2 = " morgen"
SPECTRA> say s1""s2
The last command line prints the string "guten morgen" on the terminal.

Symbols can be used in arithmetic expressions and the result of a calculation can be stored in a symbol.

Example:

SPECTRA> pi = 4$*$atan(1)
SPECTRA> sh sy "pi"
SPECTRA> $*$ = -3$*$pi
displays the numeric result
The second command displays the symbol pi. If pi were not hidden between quotation marks, it would be translated during the parsing of the command line. That would result in the command " sh sy 3.14...". Symbol value can be inspected using the wild-card character, e.g. the command
SPECTRA> sh sy p$*$
lists all symbols that begin with the letter "p".

It is also possible to search for symbols which have a certain value: symbol_alias(). Here is an example:

SPECTRA> two_theta = mot11
SPECTRA> tt = mot11
SPECTRA> $*$ = symbol_alias( mot11)
TWO_THETA, TT


Subsections