Create a transparent block protected against evaluation

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.




blockTransparent(a) creates a transparent block, which is left unchanged by evaluation, too, but treated as expression with the same operands as a.

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

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

Transparent blocks are invariant under evaluation.

Transparent blocks, on the other hand, have the same operands as their content..

Sequences can also be put into block; in the case of blockTransparent, they are not flattened. See Example 4.

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

The call expr(b) replaces all transparent blocks in b by their content, without evaluating that content. Thus, expr(blockTransparent(a)) is similar to hold(a).

In case of nested blocks, only the outermost block is removed by both expr and unblock.


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

Transparent blocks protect against evaluation, too:

y:= 2:

However, a transparent block allows access to the operands of its content:

op(bl,1), subs(bl, hold(y) = y)

delete bl, y:

Example 3

With a third kind of block, suppressing evaluation may be limited to certain identifiers:

x:= 3: y:=1:

delete x, y:

Example 4

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

block((x, y),z)

Example 5

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

y:= 1: unblock(block(y)); delete y:

Example 6

We want to create blocks that represent arithmetical expressions. To do this, we need our 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 allows us 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))

We can now manipulate this expression, without being disturbed by automatic simplification:





Any object or sequence of objects

Return Values

blockTransparent creates objects of its own type.

See Also

MuPAD Functions

Was this topic helpful?