next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc :: installAssignmentMethod

installAssignmentMethod -- install methods assignment to the value of an operator

Synopsis

Description

If the operator is a unary operator, just omit X and its comma.

We illustrate this function by defining a type of mutable list whose elements can be both extracted and replaced using the operator _. We also install a method for net so objects of the class can be printed.

i1 : M = new Type of MutableList

o1 = M

o1 : Type
i2 : net M := m -> peek m

o2 = -*Function[stdio:2:12-2:20]*-

o2 : FunctionClosure
i3 : M _ ZZ := (x,i) -> x#i

o3 = -*Function[stdio:3:17-3:22]*-

o3 : FunctionClosure
i4 : installAssignmentMethod(symbol _, M, ZZ, (x,i,v) -> x#i = v);
i5 : y = new M from (a..z)

o5 = M{a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z}

o5 : M
i6 : y_12

o6 = m

o6 : Symbol
i7 : y_12 = foo

o7 = foo

o7 : Symbol
i8 : y

o8 = M{a, b, c, d, e, f, g, h, i, j, k, l, foo, n, o, p, q, r, s, t, u, v, w, x, y, z}

o8 : M
i9 : y_12

o9 = foo

o9 : Symbol
For sample applications of this facility, see Symbol _ Thing = Thing and MutableMatrix _ Sequence = Thing.

Caveat

The syntax involved here is not pleasant, so we may change it to something briefer, something involving yet another assignment operator, distinct from = and :=.

See also

Ways to use installAssignmentMethod :