Artifact 86d59ee6a83ee97a9bf9be3bfcfbbb4bb62d8594044929779dc2b2b2bc591337:
- Executable file
r37/lisp/csl/html/r37_0211.html
— part of check-in
[f2fda60abd]
at
2011-09-02 18:13:33
on branch master
— Some historical releases purely for archival purposes
git-svn-id: https://svn.code.sf.net/p/reduce-algebra/code/trunk/historical@1375 2bfe0521-f11c-4a00-b80e-6202646ff360 (user: arthurcnorman@users.sourceforge.net, size: 2606) [annotate] [blame] [check-ins using] [more...]
<A NAME=OPERATOR> <TITLE>OPERATOR</TITLE></A> <b><a href=r37_idx.html>INDEX</a></b><p><p> <B>OPERATOR</B> _ _ _ _ _ _ _ _ _ _ _ _ <B>declaration</B><P> <P> Use the <em>operator</em> declaration to declare your own operators. <P> <H3> syntax: </H3> <P> <P> <em>operator</em><identifier>{,<identifier>}* <P> <P> <P> <identifier> can be any valid REDUCE identifier, which is not the name of a <A HREF=r37_0345.html>matrix</A>, <A HREF=r37_0188.html>array</A>, scalar variable or previously-defined operator. <P> <P> <P> <H3> examples: </H3> <P><PRE><TT> operator dis,fac; let dis(~x,~y) = sqrt(x^2 + y^2); dis(1,2); SQRT(5) dis(a,10); 2 SQRT(A + 100) on rounded; dis(1.5,7.2); 7.35459040329 let fac(~n) = if n=0 then 1 else if not(fixp n and n>0) then rederr "choose non-negative integer" else for i := 1:n product i; fac(5); 120 fac(-2); ***** choose non-negative integer </TT></PRE><P>The first operator is the Euclidean distance metric, the distance of point (x,y) from the origin. The second operator is the factorial. <P> <P> Operators can have various properties assigned to them; they can be declared <A HREF=r37_0196.html>infix</A>, <A HREF=r37_0200.html>linear</A>, <A HREF=r37_0222.html>symmetric</A>, <A HREF=r37_0187.html>antisymmetric</A>, or <A HREF=r37_0206.html>noncom</A><em>mutative</em>. The default operator is prefix, nonlinear, and commutative. Precedence can also be assigned to operators using the declaration <A HREF=r37_0213.html>precedence</A>. <P> <P> Functionality is assigned to an operator by a <A HREF=r37_0199.html>let</A> statement or a <A HREF=r37_0195.html>forall</A>...<em>let</em> statement, (or possibly by a procedure with the name of the operator). Be careful not to redefine a system operator by accident. REDUCE permits you to redefine system operators, giving you a warning message that the operator was already defined. This flexibility allows you to add mathematical rules that do what you want them to do, but can produce odd or erroneous behavior if you are not careful. <P> <P> You can declare operators from inside <A HREF=r37_0055.html>procedure</A>s, as long as they are not local variables. Operators defined inside procedures are global. A formal parameter may be declared as an operator, and has the effect of declaring the calling variable as the operator. <P> <P> <P>