Macaulay2 » Documentation
Packages » Macaulay2Doc :: installAssignmentMethod
next | previous | forward | backward | up | index | toc

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 = FunctionClosure[stdio:2:11-2:19]

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

o3 = FunctionClosure[stdio:3:16-3:21]

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 :

For the programmer

The object installAssignmentMethod is a method function.