Next: , Previous: , Up: Top   [Contents][Index]

3 Tutorial

This chapter gives an overview of the basic details of LUX. It skips many of the fine details, but gives pointers to where you can find more about such details. After reading this tutorial, you may be interested to see a listing of most of LUX’s routines by category: Routine Groups. WARNING: This chapter is new and yet incomplete.

Once you’ve installed (Installing LUX) and started up the LUX program (Start & Stop), you can type commands at the LUX> prompt (Command Input). Our first example program prints the string hello, world! on the screen. In LUX, this is simply

LUX>t,'hello, world!'
hello, world!

The LUX> at the beginning of the line is the prompt, which indicates that LUX is ready to accept your commands. The t subroutine (synonyms: type, print; t, Subroutine Call) prints its comma-separated arguments to the screen, using default output formats (Formatted Input/Output). The argument in this case is a literal string (Strings). LUX also knows about numbers. You can specify integer numbers in various bases, and also floating-point numbers with optional exponents (Scalars).

LUX distinguishes between lower case and upper case letters. Addition of arbitrary amounts of whitespace (blanks) is ignored except inside literal strings and inside names. So, the first example could also have been given as

LUX>  type  ,    'hello, world!'
hello, world!

Besides subroutines such as t, LUX also offers many functions, which take arguments and return a value (Function Call). For example,


shows the value returned by the trigonometric sine function (sin, Trigonometry) for the argument 1 (measured in radians in this case). Arguments to functions must be separated by commas, and the whole argument list must be enclosed in parentheses. You can change the format in which the result is printed (Formatted Input/Output). Besides functions, LUX knows a number of other operations that yield values (Operators), including arithmetic operators such as addition and multiplication, and also operators that compare their operands (Binary Relationals), perform binary logic on them (Binary Logic), and a number of others.

One of the strengths of LUX is that it is easy to work with large sets of numbers, in arrays (Arrays). You can specify an array by listing its members explicitly, e.g.,

         1         2         6        12

assigns a four-element array to the variable named x (Variables, Square Brackets). In assignments like this, the variable assumes the data class (Data Classes) and type, if any, of the expression that is assigned to it (Expressions): you do not need to declare the type of the variable beforehand. You can also use one of the many functions in LUX that generate arrays (Array Creation). The data values in arrays are arranged in a specific coordinate system that may have several dimensions (up to #max_dims of them, actually – #max_dims). For example, you can create an array of 3 by 4 elements which contain as values their index counted from the start of the array:

         0         1         2         3         4         5         6
         7         8         9        10        11
195 X         array, LONG, #elem = 12, (3,4)

In this example, the lonarr function (lonarr) creates and returns a long (four-byte integer, Numerical Data Types) array of 3 by 4 elements with unspecified values for its elements. The indgen function (indgen) that is applied to this array fills each element of its argument array with its index, counted from the start of the array. The d subroutine (d, a synonym of dump) displays basic information about the variable or variables that are specified as its arguments. In this case, it shows that x is a long array of 3 by 4 elements, making 12 elements in total. Note that in assignments, the variable that is assigned to loses any previous contents it might have had – in this case, the earlier contents [1,2,6,12] are deleted and replaced by the new contents. The new contents need not be of the same class or type as the old contents.

You can inspect particular elements of an array in various ways (Subscripts). The most basic way is to specify the coordinates of the element you wish, separated by commas and enclosed in parentheses, but you can also inspect ranges of elements:

         6         7         9        10

The asterisk * in the second command means "through the end of the array in the current coordinate", and the semicolons : separate the specification of the beginning of each range from the specification of the end.

You modify particular elements of an array using similar subscripts on the left-hand side of the equal sign (=):

LUX>x(2,3) = 17
LUX>x(0:1,2:*) = [1, 2, 3, 4]

Lines like the previous ones, that instruct LUX to perform a particular task, and after which LUX is ready to accept another command, are called statements. You’ve already seen assignment statements (Assignment) and subroutine calls such as the ones to subroutine t (Subroutine Call), but there are many more (Statements). You can repeat particular statements using for, repeat-until, while-do, or do-while statements. You can select particular statements for execution from a number of statements, using an if, case, or ncase statement.

Next: , Previous: , Up: Top   [Contents][Index]