Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 4558

Macaulay2-1.3.1-8.fc15.i686.rpm

<?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>installing methods</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_binary_spmethods.html">next</a> | <a href="_ancestor_lp__Type_cm__Type_rp.html">previous</a> | <a href="_binary_spmethods.html">forward</a> | <a href="_what_spa_spclass_spis.html">backward</a> | <a href="___The_sp__Macaulay2_splanguage.html">up</a> | <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>
<div><a href="index.html" title="">Macaulay2Doc</a> > <a href="___The_sp__Macaulay2_splanguage.html" title="">The Macaulay2 language</a> > <a href="_installing_spmethods.html" title="">installing methods</a></div>
<hr/>
<div><h1>installing methods</h1>
<div>The method to be used for computing an expression such as <tt>-x</tt> depends on the type of <tt>x</tt>.  For example, the method for negating a polynomial differs from the method for negating an integer modulo 111.  Each method is a function of one variable, and is stored in the class of <tt>x</tt> under a key that is referred to as the name of the method.  For some built-in methods the method name is a symbol, but for methods created with <a href="_method.html" title="make a new method function">method</a>, the method name is the same as the function used for calling it up.<p/>
Let's assume that <tt>X</tt> is the class of <tt>x</tt>.  The way to install a method for the negation of an instance <tt>x</tt> of <tt>X</tt> is with a statement of the following form.<pre>- X := x ->( ... )</pre>
Here <tt>( ... )</tt> represents the body of the function, consisting of suitable code for the operation at hand.<p/>
The method installed by the code above is automatically inherited by subclasses of X.  Here is a brief description of the way this works.  Suppose <tt>X</tt> is the <a href="_parent.html" title="parent type of an object">parent</a> of <tt>P</tt>.  When an expression <tt>-p</tt> is to be evaluated, where the class of <tt>p</tt> is <tt>P</tt>, then the method for <tt>-P</tt> is applied, unless there isn't one, in which case the method for <tt>-X</tt> is applied, and so on, all the way up the chain of parents to the topmost ancestor of everything, which is called <a href="___Thing.html" title="the class of all things">Thing</a>.<p/>
As an extreme example of inheritance, code like<pre>- Thing := x -> ...</pre>
will install a method for negating anything, which will take effect as a last resort whenever a more specifically defined method isn't found.  It probably isn't a good idea to install such a method, for usually all it can do is to print an error message.<p/>
The user may introduce new methods as well as new method names.  So it is important to understand how methods are installed and consulted.<p/>
Applying a method named <tt>C</tt> to a thing <tt>x</tt> whose class is <tt>X</tt> means that<pre>(lookup(C,X)) x</pre>
is evaluated.  In other words, <tt>C</tt> is used as a key to obtain a function from <tt>X</tt> (or its parent, grandparent, and so on), and the function is applied to <tt>x</tt>.  See <a href="_lookup.html" title="look up methods">lookup</a>.<p/>
Installing a method named <tt>C</tt> for the class <tt>X</tt> is done with code such as <pre>C X := (x) -> ( ... )</pre>
where <tt>( ... )</tt> represents suitable code for the operation at hand.<p/>
The routine for making new methods is <a href="_method.html" title="make a new method function">method</a>.</div>
<div class="single"><h2>See also</h2>
<ul><li><span><a href="_binary_spmethods.html" title="">binary methods</a></span></li>
</ul>
</div>
</div>
</body>
</html>