BlocksΒΆ

A block is a sequence of expressions evaluated in the order that they appear, except as modified by control expressions such as leave, return, iterate, and 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,

i < 0 => x

The expression before the “=>” must evaluate to true or false. The expression following the “=>” is the return value of the block.

A block can be constructed in two ways:

  1. the expressions can be separated by semicolons and the resulting expression surrounded by parentheses, and
  2. the expressions can be written on succeeding lines with each line indented the same number of spaces (which must be greater than zero). A block entered in this form is called a pile

Only the first form is available if you are entering expressions directly to FriCAS. Both forms are available in .input files. The syntax for a simple block of expressions entered interactively is

( expression1 ; expression2 ; ... ; expressionN )

The value returned by a block is the value of an => expression, or expressionN if no => is encountered.

In .input files, blocks can also be written in piles. The examples given here are assumed to come from .input files.

a :=
  i := gcd(234,672)
  i := 2*i**5 - i + 1
  1 / i

    1
  -----
  23323
            Type: Fraction Integer

In this example, we assign a rational number to a 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.

a := ( i := gcd(234,672); i := 2*i**5 - i + 1; 1 / i )

    1
  -----
  23323
            Type: Fraction Integer

Here is the same block written on one line. This is how you are required to enter it at the input prompt.

( a := 1; b := 2; c := 3; [a,b,c] )
  [1,2,3]
            Type: List PositiveInteger

As FriCAS gives you two ways of writing a block and the preferred way in an .input file is to use a pile. Roughly speaking, a pile is a block whose consituent 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. FriCAS 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.

Also See:

  • )help if
  • )help repeat
  • )help while
  • )help for
  • )help suchthat
  • )help parallel
  • )help lists

Table Of Contents

This Page