## Chapter 2Getting Started

2.1 Direct Mode

2.5 Expressions
2.5.1 Values
2.5.2 Constants
2.5.3 Variables
2.5.4 Operators
2.5.5 Functions

2.7 Commands
2.7.1 Command Format

### 2.1 Direct Mode

In this section we describe how to run ICL in direct mode and use its variables, expressions etc. which enable us to use the VAX as a very expensive electronic calculator. In direct mode we type in commands and they are executed immediately. The alternative to direct mode is the use of procedures, in which the commands are entered into a procedure, and subsequently executed by running the procedure.

ICL is started up by using the command ICL. After a short delay ICL will respond by displaying any startup messages which have been set, followed by the prompt ICL>, meaning it is now ready to accept a command.

$ICL Interactive Command Language - Version 1.5-6 - Type HELP [command] for help on ICL and its commands ICL> ### 2.2 Entering Commands When entering commands in ICL all the normal command line editing facilities available in DCL may be used. The Up arrow or CTRL/B key may be used to recall previous commands and the Down arrow key will step to the next command. Any command back to the start of the ICL session may be recalled. A command may take more than one line. A tilde ~ symbol at the end of a line is used to indicate that the command continues on the next line. ### 2.3 The Immediate Statement The first ICL statement we will introduce is the immediate statement. This is used to make ICL do simple calculations. It simply consists of an equals sign (=) followed by an expression, and causes the value of the expression to be printed on the terminal. ICL> = 1 + 2 + 3 6 ICL> = SQRT(2) 1.414214 ICL> ICL arithmetic expressions are very similar to expressions in FORTRAN, and will be discussed in more detail later. ### 2.4 The Assignment Statement The other commonly used statement is the assignment statement, which is exactly the same as the FORTRAN assignment statement, and is used to assign a value to a variable. ICL> PI = 3.1415926 ICL> = 2 * pi 6.283185 ICL> Note that the case of letters doesn’t matter. PI and pi are the same variable. ### 2.5 Expressions Expressions are built up by operating on values using operators. The values can be represented by either constants or variables or can be the result of a function operating on another expression. #### 2.5.1 Values ICL operates on values of four different types: • Integer • Real • Logical • String The integer, real and logical types are the same as their FORTRAN equivalents (the ICL real type is strictly equivalent to FORTRAN’s double precision being stored with about 16 decimal digits of precision. The String type represents strings of characters and is similar to the FORTRAN CHARACTER*n type. #### 2.5.2 Constants Values of all four types can be represented by appropriate constants. Integer and real constants are represented by numbers written in the same formats that are accepted in FORTRAN. Integer constants may also be entered in binary, octal or hexadecimal format by preceding the value with %B, %O or %X. Logical constants are typed as TRUE or FALSE. Note that they are not delimited by decimal points as in FORTRAN. String constants consist of any sequence of characters enclosed in either single or double quotes. Two consecutive quote symbols in a string are used to represent a single quote. String constants are the one place in ICL where the case of letters is significant. Some examples of constants: Real 1.234E-5 3.14159 Integer 123 %B100110 %O377 %Xffff Logical TRUE FALSE String ’This is a string’ "So is this" ’’ The last example defines a string of zero length (valid in ICL but not in FORTRAN). #### 2.5.3 Variables Variables in ICL are represented by names composed of characters which may be letters, digits or the underscore character ( _ ). The first character must be a letter. The first 15 characters of a variable name are significant (i.e. two variable names which are the same in the first 15 characters, but differ in subsequent characters refer to the same variable). An important difference between ICL and FORTRAN is in the handling of variable types. In FORTRAN each variable name has a unique type associated with it, which is either derived implicitly from the first letter of the name, or is explicitly specified in a declaration. In ICL names do not have types, only values have types. A variables gains a type when it is assigned a value. This type can change when a new value is assigned to it. Thus we can have the following sequence of assignments making the variable X an integer, real, logical and string in sequence. ICL> X = 123 ICL> X = 123.456 ICL> X = TRUE ICL> X = ’String’ This approach to variable types means we do not have to declare the variables we use which helps to keep programs simple.1 #### 2.5.4 Operators The operators which are used to build up expressions are listed in the following table. Priority 1 (highest) ** 2 * / 3 + - 4 = > < >= <= <> : 5 (lowest) NOT AND OR & The order of evaluation of expressions is determined by the priority of the operators. The rules are the same as those in FORTRAN2 with arithmetic operators having the highest priority, and logical operators the lowest. This means that a condition such as $0 can be expressed in ICL as follows X+Y > 0 AND X+Y <= 1 without requiring any parentheses. In general however, it is good practice to use parentheses to clarify any situation in which the order of evaluation is in doubt. In evaluating expressions ICL will freely apply type conversion to its operands in order to make sense of them. This means not only that integers will be converted to reals when required, but also that strings will be converted to numbers when possible. A string can be converted to a numeric value if the value of the string is itself a valid ICL expression. For example the string ’1.2345’ has a numeric value. The string ’X+1’ has a numeric value if X is currently a numeric variable (or if X is a string which has a numeric value). The operator & performs string concatenation – operands with numeric values will be converted to strings. The : operator is used for formatting numbers into character strings as described below. #### 2.5.5 Functions ICL provides a variety of standard functions. Functions are written in exactly the same way in ICL as in FORTRAN, and all the standard FORTRAN 77 generic functions which are relevant to the ICL data types are provided in ICL with the same names as in FORTRAN. Thus SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2, LOG, LOG10, EXP, SQRT and ABS are all valid functions. A more complete list of functions is given in Appendix A. ### 2.6 Formatting Numbers For Output While FORTRAN regards formatting of numbers for output as part of an output operation, ICL performs formatting using an operator (:), which produces a string result from a numeric operand. Thus if I is an integer variable the expression I:5 has as its value the string which is produced by converting I with a field width of 5 characters. Thus it is equivalent to an I5 format in FORTRAN. Similarly if X is a real variable the expression X:10:4 produces the value of X formatted in a FORTRAN F10.4 format (i.e. a field width of 10 characters, and four decimal places). The ICL formatting is not precisely equivalent to the FORTRAN form because ICL will extend the field width if a number is too large to fit in the requested width. ICL> = 1.234567:5:2 1.23 ICL> = 12.34567:5:2 12.35 ICL> = 123.4567:5:2 123.46 ICL> = 123456.7:5:2 123456.70 Integers can also be formatted in binary, octal, decimal or hexadecimal formats using the functions BIN, OCT, DEC and HEX. These have the form HEX(X,n,m) which would return a string of n characters containing the number X with m significant digits. n and m may be omitted in which case they default to the number of digits needed to represent a full 32 bit word. Using these forms together with constants in various bases, ICL can be used to perform conversions between various bases. ICL> = %Xffff 65535 ICL> = hex(65535) 0000FFFF ICL> = OCT(%XFF,5,5) 00377 ### 2.7 Commands We have now met two of the three statement types available in direct mode, the immediate and assignment statements. We now introduce the third and most important one, the command. Commands are used for three purposes. • To provide features of the ICL system itself — These are commands such as PRINT, EDIT, LIST etc. • To call procedures written in ICL. • To provide the commands of the system ICL is being used to run — In this case ADAM. #### 2.7.1 Command Format An ICL command consists of a command name, which is formed using exactly the same rules as we described earlier for variable names, followed by optionally, one or more parameters. Parameters can take three forms: • An expression or variable name enclosed in parentheses. • A string enclosed in quotes. • Any sequence of characters not including a space, quote, comma or left parenthesis. The parameters may be separated by commas, or by one or more spaces. The first form of the parameter is used when we want to pass the value of an expression to the command, or we want to give the command a variable into which it will return a value. The other two forms both pass a string. We can illustrate these various cases by using the PRINT command, which prints its parameters on the terminal. ICL> X=1.234 ICL> PRINT (X) 1.23400 ICL> PRINT ’HELLO’ HELLO ICL> PRINT HELLO HELLO In most cases therefore we do not need to use the quoted form of string parameters because the simpler form will work. We need the quoted form of strings for those cases in which we need to include a left parenthesis, or spaces in the string. Here is an example with several parameters. ICL> X=2 ICL> PRINT The Square Root of (X) is (SQRT(X)) The Square Root of 2 is 1.414214 What is happening here is that, since spaces are parameter separators, ’The’, ’Square’, ’Root’ and ’of’ are all received by PRINT as independent parameters. However PRINT simply concatenates all its parameters, with a space between each pair, and thus the result is the string just as we typed it. Many other ICL commands which accept strings work in this way. This means that strings with single spaces do not usually need quotes when used as command parameters. #### 2.7.2 Summary of Rules for Command Parameters The rules for specifying command parameters can be summarized as follows. • To pass the value of an expression (which might be just a single number), or the name of a variable, the expression or variable should be placed in parentheses. • Anything not in parentheses is passed as a string, or as a sequence of strings if it contains spaces or commas. • Any string which does not fit these restrictions, can be passed by placing it in quotes. FORTRAN programmers may find it useful to note that the parenthesized form of the command parameters is exactly equivalent to the normal FORTRAN method of passing parameters to a subroutine. Thus the ICL command COMMAND (A) (B) (C) is equivalent to the FORTRAN CALL COMMAND (A, B, C) Any parameter can always be passed in this way. The other forms of parameter simply provide a convenient way of handling the common case of passing a string constant. These rules may appear somewhat confusing specified in this way, but what they achieve is to allow us to type many familiar commands in the way we are used to. Thus the following are valid ICL commands: ICL>$DIR/SIZE/DATE/SINCE=TODAY

ICL> SPLOT MYSPECT LOW=10 HIGH=100 \

1The disadvantage is that ICL cannot usually spot cases where we accidentally mistype the name of a variable, as can languages which enforce declaration of variables (such as FORTRAN with the IMPLICIT NONE directive). This is not thought to be a serious problem for the relatively simple programs for which ICL is intended.

2But different from those in Pascal