<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>installAssignmentMethod -- install methods assignment to the value of an operator</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_install__Hilbert__Function.html">next</a> | <a href="_insert_lp__Z__Z_cm__Thing_cm__Visible__List_rp.html">previous</a> | <a href="_install__Hilbert__Function.html">forward</a> | <a href="_insert_lp__Z__Z_cm__Thing_cm__Visible__List_rp.html">backward</a> | up | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <hr/> <div><h1>installAssignmentMethod -- install methods assignment to the value of an operator</h1> <div class="single"><h2>Synopsis</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>installAssignmentMethod(op,X,Y,f)</tt></div> </dd></dl> </div> </li> <li><div class="single">Inputs:<ul><li><span><tt>op</tt>, <span>a <a href="___Keyword.html">keyword</a></span>, the symbol for a binary operator</span></li> <li><span><tt>X</tt>, <span>a <a href="___Type.html">type</a></span>, the type of the left-hand operand</span></li> <li><span><tt>Y</tt>, <span>a <a href="___Type.html">type</a></span>, the type of the right-hand operand</span></li> <li><span><tt>f</tt>, <span>a <a href="___Function.html">function</a></span>, the method function that will perform the assignment</span></li> </ul> </div> </li> <li><div class="single">Consequences:<ul><li>If the operator to be used is <tt>**</tt>, say, then <tt>op</tt> should be <tt>symbol **</tt>. After installing the assignment method, assignments of the form <tt>x**y=v</tt> will be handled by evaluating <tt>f(x,y,v)</tt>.</li> </ul> </div> </li> </ul> </div> <div class="single"><h2>Description</h2> <div><p>If the operator is a unary operator, just omit <tt>X</tt> and its comma.</p> <p>We illustrate this function by defining a type of mutable list whose elements can be both extracted and replaced using the operator <tt>_</tt>. We also install a method for <a href="_net.html" title="format for printing, as a net">net</a> so objects of the class can be printed.</p> <table class="examples"><tr><td><pre>i1 : M = new Type of MutableList o1 = M o1 : Type</pre> </td></tr> <tr><td><pre>i2 : net M := m -> peek m o2 = {*Function[stdio:2:11-2:19]*} o2 : FunctionClosure</pre> </td></tr> <tr><td><pre>i3 : M _ ZZ := (x,i) -> x#i o3 = {*Function[stdio:3:16-3:21]*} o3 : FunctionClosure</pre> </td></tr> <tr><td><pre>i4 : installAssignmentMethod(symbol _, M, ZZ, (x,i,v) -> x#i = v);</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>i6 : y_12 o6 = m o6 : Symbol</pre> </td></tr> <tr><td><pre>i7 : y_12 = foo o7 = foo o7 : Symbol</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>i9 : y_12 o9 = foo o9 : Symbol</pre> </td></tr> </table> For sample applications of this facility, see <a href="___Symbol_sp_us_sp__Thing_sp_eq_sp__Thing.html" title="assignment to an indexed variable">Symbol _ Thing = Thing</a> and <a href="___Mutable__Matrix_sp_us_sp__Sequence_sp_eq_sp__Thing.html" title="assignment to an element of a mutable matrix">MutableMatrix _ Sequence = Thing</a>.</div> </div> <div class="single"><h2>Caveat</h2> <div>The syntax involved here is not pleasant, so we may change it to something briefer, something involving yet another assignment operator, distinct from <tt>=</tt> and <tt>:=</tt>.</div> </div> <div class="single"><h2>See also</h2> <ul><li><span><a href="___Mutable__List.html" title="the class of all mutable lists">MutableList</a> -- the class of all mutable lists</span></li> <li><span><a href="___Basic__List_sp_sh_sp__Z__Z.html" title="get element from list">BasicList # ZZ</a> -- get element from list</span></li> </ul> </div> <div class="waystouse"><h2>Ways to use <tt>installAssignmentMethod</tt> :</h2> <ul><li>installAssignmentMethod(Symbol,HashTable,Function)</li> <li>installAssignmentMethod(Symbol,HashTable,HashTable,Function)</li> <li>installAssignmentMethod(Symbol,HashTable,HashTable,Option)</li> <li>installAssignmentMethod(Symbol,HashTable,Option)</li> </ul> </div> </div> </body> </html>