5. More on variables The previous examples only used single-letter variable names. In fact it is more useful to have whole words as variable names, and Rexx allows this up to an implementation maximum (which should be suitably large, e.g. 250 characters). Moreover, not only letters but numbers and the three characters "!", "?" and "_" are allowed in variable names - or "symbols", as they are generally called. These are valid symbols: fred Dan_Yr_0gof HI! The case of letters is unimportant, so that for example "Hello", "HELLO" and "hellO" all mean the same. If you use a symbol in an expression when it has not been previously given a value, that does not cause an error (unless "signal on novalue" is set - see later). Instead, it just results in its own name translated into upper case. /* A demonstration of simple symbols */ foo=3 bar="Characters" say foo bar':' hi! This program says "3 Characters: HI!". As well as "simple symbols", which are variables like the above, there are arrays (strictly speaking, they are not called arrays in Rexx but "stem variables", though equivalent things in other languages are called "associative arrays"). Any ordinary variable name can also be used as the name of an array: /* This program uses an array. */ pull a array.1=a array.2=a*a array.3=a**3 say array.1 array.2 array.3 array.1+array.2+array.3 An element of an array is accessed by typing the array name, a dot, and the element number. The array name and the dot are together known as the "stem" of the array. The rest of the element's name is known as the "tail" of the name. The stem and tail together are called "a compound symbol". Note that an array does not have to be declared before it is used. Also note that the simple variable "a" and the stem "a." refer to completely separate variables. In fact not only numbers, but strings and variable names may be used as element names. Also, an element name can consist of two or more parts separated by dots, so giving two or more dimensional arrays. /* This program uses an array with various elements */ book.1.author="M. F. Cowlishaw" book.1.title="The REXX Language, a practical approach to programming" book.1.pub="Englewood Cliffs 1985" book.2.author="A. S. Rudd" book.2.title="Practical Usage of REXX" book.2.pub="Ellis Horwood 1990" /* insert lots more */ say "Input a book number" pull i say "Author: " book.i.author say "Title: " book.i.title say "Publisher:" book.i.pub In the above program, a stem variable called "book" is created, containing a number of records each with elements AUTHOR, TITLE and PUB. Notice that these three uppercase names are produced by symbols "author", "title" and "pub", because those symbols have not been given values. When a book number i has been input, the elements of the (i)th record are printed out. It is not an error to reference an undefined element of a stem variable. If you type "3" into the above program, you will see this: Input a book number 3 Author: BOOK.3.AUTHOR Title: BOOK.3.TITLE Publisher: BOOK.3.PUB As before, if a compound symbol has not been given a value, then its name is used instead. There is a way to initialise every element of a stem variable: by assigning a value to the stem itself. Edit the above program and insert after the comment line: book.="Undefined" This gives every possible element of the stem variable the value "Undefined", so that if you again type "3" you will see the following: Input a book number 3 Author: Undefined Title: Undefined Publisher: Undefined