File: gprolog026.html

package info (click to toggle)
gprolog 1.3.0-6.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 13,512 kB
  • ctags: 8,954
  • sloc: ansic: 57,431; perl: 16,620; sh: 5,900; makefile: 1,284
file content (158 lines) | stat: -rw-r--r-- 5,966 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="gprolog.css">
<TITLE>
Term comparison
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="gprolog025.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="gprolog023.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="gprolog027.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H3 CLASS="subsection"><A NAME="htoc72">7.3</A>&nbsp;&nbsp;Term comparison</H3><UL>
<LI><A HREF="gprolog026.html#toc48">Standard total ordering of terms</A>
<LI><A HREF="gprolog026.html#toc49"><TT>(==)/2</TT> - term identical,
 <TT>(\==)/2</TT> - term not identical,<BR>
<TT>(@&lt;)/2</TT> - term less than,
 <TT>(@=&lt;)/2</TT> - term less than or equal to,<BR>
<TT>(@&gt;)/2</TT> - term greater than,
 <TT>(@&gt;=)/2</TT> - term greater than or equal to</A>
<LI><A HREF="gprolog026.html#toc50"><TT>compare/3</TT></A>
</UL>

<A NAME="toc48"></A>
<H4 CLASS="subsubsection"><A NAME="htoc73">7.3.1</A>&nbsp;&nbsp;Standard total ordering of terms</H4>
<A NAME="Standard-total-ordering-of-terms"></A>
The built-in predicates described in this section allows the user to compare
Prolog terms. Prolog terms are totally ordered according to the standard
total ordering of terms which is as follows (from the smallest term to the
greatest):
<UL CLASS="itemize"><LI CLASS="li-itemize">variables, oldest first.<BR>
<BR>
<LI CLASS="li-itemize">finite domain variables (section&nbsp;<A HREF="gprolog055.html#Finite-Domain-variables">8.1.1</A>), oldest
first.<BR>
<BR>
<LI CLASS="li-itemize">floating point numbers, in numeric order. <BR>
<BR>
<LI CLASS="li-itemize">integers, in numeric order. <BR>
<BR>
<LI CLASS="li-itemize">atoms, in alphabetical (i.e. character code) order. <BR>
<BR>
<LI CLASS="li-itemize">compound terms, ordered first by arity, then by the name of the
principal functor and by the arguments in left-to-right order.</UL>
A list is treated as a compound term (whose principal functor is
<TT>'.'/2</TT>).<BR>
<BR>
The portability of the order of variables is not guaranteed (in the ISO
reference the oder of variables is system dependent).<BR>
<BR>
<A NAME="toc49"></A>
<H4 CLASS="subsubsection"><A NAME="htoc74">7.3.2</A>&nbsp;&nbsp;<TT>(==)/2</TT> - term identical,
 <TT>(\==)/2</TT> - term not identical,<BR>
<TT>(@&lt;)/2</TT> - term less than,
 <TT>(@=&lt;)/2</TT> - term less than or equal to,<BR>
<TT>(@&gt;)/2</TT> - term greater than,
 <TT>(@&gt;=)/2</TT> - term greater than or equal to</H4>
<A NAME="(==)/2"></A> 
 
 
 
 
 
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
==(?term, ?term)<BR>
\==(?term, ?term)<BR>
@&lt;(?term, ?term)<BR>
@=&lt;(?term, ?term)<BR>
@&gt;(?term, ?term)<BR>
@&gt;=(?term, ?term)</TT></DL>
<B>Description</B><BR>
<BR>
These predicates compare two terms according to the standard total ordering
of terms (section&nbsp;<A HREF="#Standard-total-ordering-of-terms">7.3.1</A>).<BR>
<BR>
<TT>Term1 == Term2</TT> succeeds if <TT>Term1</TT> and <TT>Term2</TT> are
equal. <BR>
<BR>
<TT>Term1 \== Term2</TT> succeeds if <TT>Term1</TT> and
<TT>Term2</TT> are different.<BR>
<BR>
<TT>Term1 @&lt; Term2</TT> succeeds if <TT>Term1</TT> is less than
<TT>Term2</TT>.<BR>
<BR>
<TT>Term1 @=&lt; Term2</TT> succeeds if <TT>Term1</TT> is less than or
equal to <TT>Term2</TT>.<BR>
<BR>
<TT>Term1 @&gt; Term2</TT> succeeds if <TT>Term1</TT> is greater than
<TT>Term2</TT>.<BR>
<BR>
<TT>Term1 @&gt;= Term2</TT> succeeds if <TT>Term1</TT> is greater than
or equal to <TT>Term2</TT>.<BR>
<BR>
<TT>==</TT>, <TT>\==</TT>, <TT>@&lt;</TT>, <TT>@=&lt;</TT>,
<TT>@&gt;</TT> and <TT>@&gt;=</TT> are predefined infix operators (section&nbsp;<A HREF="gprolog037.html#op/3:(Term-input/output)">7.14.10</A>).<BR>
<BR>
<B>Errors</B><BR>
<BR>
None.<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO predicates.<BR>
<BR>
<A NAME="toc50"></A>
<H4 CLASS="subsubsection"><A NAME="htoc75">7.3.3</A>&nbsp;&nbsp;<TT>compare/3</TT></H4>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
compare(?atom, +term, +term)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>compare(Result, Term1, Term2)</TT> compares <TT>Term1</TT> and
<TT>Term2</TT> according to the standard (section&nbsp;<A HREF="#Standard-total-ordering-of-terms">7.3.1</A>) and unifies <TT>Result</TT> with:
<UL CLASS="itemize"><LI CLASS="li-itemize">the atom <TT>&lt;</TT> if <TT>Term1</TT> is less than <TT>Term2</TT>.<BR>
<BR>
<LI CLASS="li-itemize">the atom <TT>=</TT> if <TT>Term1</TT> and <TT>Term2</TT> are equal.<BR>
<BR>
<LI CLASS="li-itemize">the atom <TT>&gt;</TT> if <TT>Term1</TT> is greater than
<TT>Term2</TT>.</UL>
<B>Errors</B><BR>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Result</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP>&nbsp;&nbsp;</TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, Result)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR></TABLE><BR>
<B>Portability</B><BR>
<BR>
GNU Prolog predicate.<BR>
<BR>

<HR SIZE=2>
Copyright (C) 1999-2007 Daniel Diaz
<BR>
<BR>
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved. <BR>
<BR>
<A HREF="index.html#copyright">More about the copyright</A>
<HR>
<A HREF="gprolog025.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="gprolog023.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="gprolog027.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>