<HTML> <HEAD> <!-- Created by texi2html 1.56k + clip patches and <A href="http://www.clip.dia.fi.upm.es/Software">lpdoc</A> from ciao.texi on 28 January 2007 --> <LINK rel="stylesheet" href="ciao.css" type="text/css"> <TITLE>The Ciao Prolog System - Defining operators</TITLE> </HEAD> <BODY> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_39.html">previous</A>, <A HREF="ciao_41.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. <P><HR><P> <H1><A NAME="SEC210" HREF="ciao_toc.html#TOC210">Defining operators</A></H1> <P> <A NAME="IDX2926"></A> <P> <STRONG>Author(s):</STRONG> Adapted from SICStus 0.6 code; modifications and documentation by Daniel Cabeza and Manuel Carro. <P> <STRONG>Version:</STRONG> 1.10#7 (2006/4/26, 19:22:13 CEST) <P> <STRONG>Version of last change:</STRONG> 1.9#287 (2004/2/13, 18:59:4 CET) <P> Operators allow writting terms in a more clear way than the standard functional notation. Standard operators in Ciao are defined by this predicate (but note that the compiler itself defines more operators at compile time): <PRE> standard_ops :- op(1200,xfx,[:-]), op(1200,fx,[:-,?-]), op(1100,xfy,[;]), op(1050,xfy,[->]), op(1000,xfy,[',']), op(900,fy,[\+]), op(700,xfx,[=,\=,==,\==,@<,@>,@=<,@>=,=..,is,=:=,=\=,<,=<,>,>=]), op(550,xfx,[:]), op(500,yfx,[+,-,/\,\/,#]), op(500,fy,[++,--]), op(400,yfx,[*,/,//,rem,mod,<<,>>]), op(200,fy,[+,-,\]), op(200,xfx,[**]), op(200,xfy,[^]). </PRE> <UL> <LI><A HREF="ciao_40.html#SEC211">Usage and interface (operators)</A> <LI><A HREF="ciao_40.html#SEC212">Documentation on exports (operators)</A> </UL> <H2><A NAME="SEC211" HREF="ciao_toc.html#TOC211">Usage and interface (<CODE>operators</CODE>)</A></H2> <div class="cartouche"> <UL> <LI><STRONG>Library usage:</STRONG> <CODE>:- use_module(library(operators)).</CODE> <LI><STRONG>Exports:</STRONG> <UL> <LI><EM>Predicates:</EM> <A NAME="IDX2927"></A> <CODE>op/3</CODE>, <A NAME="IDX2928"></A> <CODE>current_op/3</CODE>, <A NAME="IDX2929"></A> <CODE>current_prefixop/3</CODE>, <A NAME="IDX2930"></A> <CODE>current_infixop/4</CODE>, <A NAME="IDX2931"></A> <CODE>current_postfixop/3</CODE>. </UL> </UL> </div class="cartouche"> <H2><A NAME="SEC212" HREF="ciao_toc.html#TOC212">Documentation on exports (<CODE>operators</CODE>)</A></H2> <P> <A NAME="IDX2932"></A> <A NAME="IDX2933"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>op/3:</B> <DD><A NAME="IDX2934"></A> <P> <CODE>op(Precedence, Type, Name)</CODE> <P> Declares the atom <CODE>Name</CODE> to be an operator of the stated <CODE>Type</CODE> and <CODE>Precedence</CODE> (0 =< <CODE>Precedence</CODE> =< 1200). <CODE>Name</CODE> may also be a list of atoms in which case all of them are declared to be operators. If <CODE>Precedence</CODE> is 0 then the operator properties of <CODE>Name</CODE> (if any) are cancelled. Note that, unlike in <A NAME="IDX2935"></A> ISO-Prolog, it is allowed to define two operators with the same name, one infix and the other postfix. <P> <STRONG>Usage:</STRONG> <CODE>op(+int, +operator_specifier, +atm_or_atm_list)</CODE> <KBD> * ISO * </KBD> <UL> <LI><EM>The following properties hold globally:</EM> This predicate is understood natively by CiaoPP. (<CODE>basic_props:native/1</CODE>) </UL> </DL> <P> <A NAME="IDX2936"></A> <A NAME="IDX2937"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>current_op/3:</B> <DD><A NAME="IDX2938"></A> <P> <CODE>current_op(Precedence, Type, Op)</CODE> <P> The atom <CODE>Op</CODE> is currently an operator of type <CODE>Type</CODE> and precedence <CODE>Precedence</CODE>. Neither <CODE>Op</CODE> nor the other arguments need be instantiated at the time of the call; i.e., this predicate can be used to generate as well as to test. <P> <STRONG>Usage:</STRONG> <CODE>current_op(?int, ?operator_specifier, ?atm)</CODE> <KBD> * ISO * </KBD> <UL> <LI><EM>The following properties hold globally:</EM> This predicate is understood natively by CiaoPP. (<CODE>basic_props:native/1</CODE>) </UL> </DL> <P> <A NAME="IDX2939"></A> <A NAME="IDX2940"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>current_prefixop/3:</B> <DD><A NAME="IDX2941"></A> <P> <CODE>current_prefixop(Op, Less, Precedence)</CODE> <P> Similar to <A NAME="IDX2942"></A> <CODE>current_op/3</CODE>, but it concerns only the prefix operators. It returns <STRONG>only one solution</STRONG>. Not a predicate for general use. </DL> <P> <A NAME="IDX2943"></A> <A NAME="IDX2944"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>current_infixop/4:</B> <DD><A NAME="IDX2945"></A> <P> <CODE>current_infixop(Op, LeftLess, Prec, RightLess)</CODE> <P> Similar to <A NAME="IDX2946"></A> <CODE>current_op/3</CODE>, but it concerns only infix operators. It returns <STRONG>only one solution</STRONG>. Not a predicate for general use. </DL> <P> <A NAME="IDX2947"></A> <A NAME="IDX2948"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>current_postfixop/3:</B> <DD><A NAME="IDX2949"></A> <P> <CODE>current_postfixop(Op, Less, Precedence)</CODE> <P> Similar to <A NAME="IDX2950"></A> <CODE>current_op/3</CODE>, but it concerns only the postfix operators. It returns <STRONG>only one solution</STRONG>. Not a predicate for general use. </DL> <P><HR><P> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_39.html">previous</A>, <A HREF="ciao_41.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. </BODY> </HTML>