]>
A block is a sequence of expressions evaluated in the order that they appear, except as modified by control expressions such as break, break return, return iterate and iterate if-then-else constructions. The value of a block is the value of the expression last evaluated in the block.
To leave a block early, use ``=>''. For example, . The expression before the ``=>'' must evaluate to true or false. The expression following the ``=>'' is the return value for the block.
A block can be constructed in two ways:
Only the first form is available if you are entering expressions directly to Axiom. Both forms are available in .input files.
The syntax for a simple block of expressions entered interactively is
( ; ; ...; )
The value returned by a block is the value of an => expression,
or if no => is encountered.
In .input files, blocks can also be written using piles. The examples throughout this book are assumed to come from .input files.
In this example, we assign a rational number to using a block consisting of three expressions. This block is written as a pile. Each expression in the pile has the same indentation, in this case two spaces to the right of the first line.
Here is the same block written on one line. This is how you are required to enter it at the input prompt.
Blocks can be used to put several expressions on one line. The value returned is that of the last expression.
Axiom gives you two ways of writing a block and the preferred way in an .input file is to use a pile. file:input Roughly speaking, a pile is a block whose constituent expressions are indented the same amount. You begin a pile by starting a new line for the first expression, indenting it to the right of the previous line. You then enter the second expression on a new line, vertically aligning it with the first line. And so on. If you need to enter an inner pile, further indent its lines to the right of the outer pile. Axiom knows where a pile ends. It ends when a subsequent line is indented to the left of the pile or the end of the file.
Blocks can be used to perform several steps before an assignment (immediate or delayed) is made.
Blocks can be used in the arguments to functions. (Here is assigned .)
Here the second argument to eval is , where the value of is computed in the first line of the block starting on the second line.
Blocks can be used in the clauses of if-then-else expressions (see ugLangIf ).
This is the pile version of the last block.
Blocks can be nested.
This is the pile version of the last block.
Since does equal , has the value of and the last line is never evaluated.