Create an object protected against evaluation

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.




block(a) creates a block — an object of special type that contains an unevaluated copy of a. It is treated as atomic and remains unchanged by evaluation.

block and domains derived thereof form a hierarchy of data types designed to provide control over the evaluation of certain subexpressions. Any object can be put as content into any type of block.

block is a domain If d is any block domain, d(a) creates a block belonging to that domain, with content a.

block(a) puts its argument into a block, without evaluating it. In order to evaluate a normally before putting it into a block, use eval(hold(block)(a)).

Blocks are invariant under evaluation.

Blocks of type block are atomic: the only operand of a block is the block itself.

Sequences can also be put into blocks. In the case of block, they are not flattened. See Example 2.

You can create further block domains using inheritance. This particularly useful for creating own evaluate or testtype methods. See Example 4.

In case of nested blocks, expr and unblock remove only the outermost block.


Example 1

A block is a sort of container that protects its content against evaluation:

y := 1:
bl:= block(1 + y)

Blocks are atomic; thus y and 1 are not visible as operands:

op(bl), nops(bl)

Although blocks are not arithmetical expressions, some basic arithmetical operations are defined for them:

collect(x + bl + x*bl, bl)

delete y, bl

Example 2

A block can also contain a sequence; flattening is suppressed:

block((x, y),z)

Example 3

The content of a block can be extracted and evaluated using unblock:

y := 1:

delete y

Example 4

Create blocks that represent arithmetical expressions. To do this, you need your own block domain that overloads testtype:

domain myblock 
  inherits block; 
  category  Cat::BaseCategory;
  testtype:= (bl, T) -> if T = Type::Arithmetical or T = dom then 
                          block::testtype(bl, T) 

This lets you to make the number zero invisible for the evaluator by enclosing it into a block, but to retain the option to plug it into special functions:

f := sin(x+myblock(0))

Now you can manipulate this expression, without being disturbed by automatic simplification:





Any object or sequence of objects

Return Values

block creates objects of its own type.

See Also

MuPAD Functions