mutable - Maple Help

type/mutable

check if an object is or contains mutable objects

 Calling Sequence type(expr, mutable)

Parameters

 expr - expression

Description

 • The type(expr, mutable) calling sequence returns true if if expr is a mutable object or contains mutable objects.
 • A mutable object is a Maple expression whose contents can change without its identity changing. The mutable objects in Maple are of type table (which includes array), rtable (which includes Array, Vector, and Matrix), module (which includes record and object), and procedure.
 • For example, an element in an Array can be changed, yet it is still the same Array, so an array is mutable. On the other hand, "changing" an element in a list creates a new list, and any references to the original list will not see the change. A list is immutable.
 • A procedure is considered mutable because it can have a remember table (even if it does not have the remember option).

Examples

 > $\mathrm{type}\left(3.14,\mathrm{mutable}\right)$
 ${\mathrm{false}}$ (1)
 > $\mathrm{type}\left(\mathrm{table}\left(\right),\mathrm{mutable}\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{type}\left(\mathrm{Vector}\left[\mathrm{row}\right]\left(\left[a,b,c\right]\right),\mathrm{mutable}\right)$
 ${\mathrm{true}}$ (3)

In general, a list is not mutable.

 > $L≔\left[a,b,\left[c,d\right]\right]$
 ${L}{≔}\left[{a}{,}{b}{,}\left[{c}{,}{d}\right]\right]$ (4)
 > $\mathrm{L0}≔L$
 ${\mathrm{L0}}{≔}\left[{a}{,}{b}{,}\left[{c}{,}{d}\right]\right]$ (5)

This does not change the lists in-place, and in fact this syntax for "changing" a list is only supported for small lists, as it is very inefficient.

 > $L\left[3\right]\left[2\right]≔e$
 ${\left({{L}}_{{3}}\right)}_{{2}}{≔}{e}$ (6)
 > $L$
 $\left[{a}{,}{b}{,}\left[{c}{,}{e}\right]\right]$ (7)

The original lists are unchanged, because lists are not mutable.

 > $\mathrm{L0}$
 $\left[{a}{,}{b}{,}\left[{c}{,}{d}\right]\right]$ (8)
 > $\mathrm{type}\left(L,\mathrm{mutable}\right)$
 ${\mathrm{false}}$ (9)

A list containing an Array is mutable because the Array is mutable.

 > $L≔\left[a,b,\mathrm{Array}\left(\left[c,d\right]\right)\right]$
 ${L}{≔}\left[{a}{,}{b}{,}\left[\begin{array}{cc}{c}& {d}\end{array}\right]\right]$ (10)
 > $\mathrm{L0}≔L$
 ${\mathrm{L0}}{≔}\left[{a}{,}{b}{,}\left[\begin{array}{cc}{c}& {d}\end{array}\right]\right]$ (11)

This changes the contents of the Array in-place, and thus the containing list is unaffected.

 > $L\left[3\right]\left[2\right]≔e$
 ${\left({{L}}_{{3}}\right)}_{{2}}{≔}{e}$ (12)
 > $L$
 $\left[{a}{,}{b}{,}\left[\begin{array}{cc}{c}& {e}\end{array}\right]\right]$ (13)
 > $\mathrm{L0}$
 $\left[{a}{,}{b}{,}\left[\begin{array}{cc}{c}& {e}\end{array}\right]\right]$ (14)
 > $\mathrm{type}\left(L,\mathrm{mutable}\right)$
 ${\mathrm{true}}$ (15)