Sponsored links: Algebra eBooks

### The Maxima on-line user's manual

Algebra Calculator

#### Block

Function: block ([<v_1>, ..., <v_m>], <expr_1>, ..., <expr_n>)

Function: block (<expr_1>, ..., <expr_n>) `block` evaluates <expr_1>, ..., <expr_n> in sequence and returns the value of the last expression evaluated. The sequence can be modified by the `go`, `throw`, and `return` functions. The last expression is <expr_n> unless `return` or an expression containing `throw` is evaluated. Some variables <v_1>, ..., <v_m> can be declared local to the block; these are distinguished from global variables of the same names. If no variables are declared local then the list may be omitted. Within the block, any variable other than <v_1>, ..., <v_m> is a global variable.

`block` saves the current values of the variables <v_1>, ..., <v_m> (if any) upon entry to the block, then unbinds the variables so that they evaluate to themselves. The local variables may be bound to arbitrary values within the block but when the block is exited the saved values are restored, and the values assigned within the block are lost.

The declaration `local(<v_1>, ..., <v_m>)` within `block` saves the properties associated with the symbols <v_1>, ..., <v_m>, removes any properties before evaluating other expressions, and restores any saved properties on exit from the block. Some declarations are implemented as properties of a symbol, including `:=`, `array`, `dependencies`, `atvalue`, `matchdeclare`, `atomgrad`, `constant`, `nonscalar`, `assume`, and some others. The effect of `local` is to make such declarations effective only within the block; otherwise declarations within a block are actually global declarations.

`block` may appear within another `block`. Local variables are established each time a new `block` is evaluated. Local variables appear to be global to any enclosed blocks. If a variable is non-local in a block, its value is the value most recently assigned by an enclosing block, if any, otherwise, it is the value of the variable in the global environment. This policy may coincide with the usual understanding of "dynamic scope".

The value of the block is the value of the last statement or the value of the argument to the function `return` which may be used to exit explicitly from the block. The function `go` may be used to transfer control to the statement of the block that is tagged with the argument to `go`. To tag a statement, precede it by an atomic argument as another statement in the block. For example: `block ([x], x:1, loop, x: x+1, ..., go(loop), ...)`. The argument to `go` must be the name of a tag appearing within the block. One cannot use `go` to transfer to a tag in a block other than the one containing the `go`.

Blocks typically appear on the right side of a function definition but can be used in other places as well.

There are also some inexact matches for `block`. Try `?? block` to see them.

```(%o1)                                true
(%i2) ```

### Related Examples

##### block-do-next_prime-print

sequence(maxCount):=b...

sequence(13);

Calculate

##### block-length-ratsimp-sum-tab

lagrange(tab) := bloc...

lagrange([[1,1],[2,4]...

lagrange([[1,-1],[2,-...

Calculate

##### block-buildq-lambda-macroexpand-map-sublist_indices

diffform(vars, expr) ...

macroexpand( diffform...

Calculate

##### block-do-next_prime-print

sequence(maxCount):=b...

sequence(13);

Calculate

##### block-length-ratsimp-sum-tab

lagrange(tab) := bloc...

lagrange([[1,3],[2,4]...

Calculate

##### block-do-next_prime-print

sequence(maxCount):=b...

sequence(13);

Calculate

##### block-cholesky-copymatrix-exp-expand-fundef-grind-length-makelist-matrix-sqrt-string-sum

aa + 1729;

grind (%);

[aa, 1729, aa + 1729];

Calculate

##### block-cos-find_root-float-kill-return

f(x):=cos(%pi*x)-4^x+1;

y[1]:0;

y[2]:1/2;

Calculate

##### block-buildq-indices-lambda-macroexpand-map-sublist_indices

diffform(vars, expr) ...

macroexpand( diffform...

diffform...

Calculate

##### block-buildq-lambda-macroexpand-map-sublist_indices

diffform(vars, expr) ...

macroexpand( diffform...

Calculate