/usr/lib/swi-prolog/doc/Manual/SyntaxAndSemantics.html is in swi-prolog-nox 5.10.4-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>SWI-Prolog 5.11.18 Reference Manual: Section 7.2</TITLE><LINK REL=home HREF="index.html">
<LINK REL=contents HREF="Contents.html">
<LINK REL=index HREF="DocIndex.html">
<LINK REL=summary HREF="summary.html">
<LINK REL=previous HREF="chrintro.html">
<LINK REL=next HREF="practical.html">
<STYLE type="text/css">
/* Style sheet for SWI-Prolog latex2html
*/
dd.defbody
{ margin-bottom: 1em;
}
dt.pubdef
{ background-color: #c5e1ff;
}
dt.multidef
{ background-color: #c8ffc7;
}
.bib dd
{ margin-bottom: 1em;
}
.bib dt
{ float: left;
margin-right: 1.3ex;
}
pre.code
{ margin-left: 1.5em;
margin-right: 1.5em;
border: 1px dotted;
padding-top: 5px;
padding-left: 5px;
padding-bottom: 5px;
background-color: #f8f8f8;
}
div.navigate
{ text-align: center;
background-color: #f0f0f0;
border: 1px dotted;
padding: 5px;
}
div.title
{ text-align: center;
padding-bottom: 1em;
font-size: 200%;
font-weight: bold;
}
div.author
{ text-align: center;
font-style: italic;
}
div.abstract
{ margin-top: 2em;
background-color: #f0f0f0;
border: 1px dotted;
padding: 5px;
margin-left: 10%; margin-right:10%;
}
div.abstract-title
{ text-align: center;
padding: 5px;
font-size: 120%;
font-weight: bold;
}
div.toc-h1
{ font-size: 200%;
font-weight: bold;
}
div.toc-h2
{ font-size: 120%;
font-weight: bold;
margin-left: 2em;
}
div.toc-h3
{ font-size: 100%;
font-weight: bold;
margin-left: 4em;
}
div.toc-h4
{ font-size: 100%;
margin-left: 6em;
}
span.sec-nr
{
}
span.sec-title
{
}
span.pred-ext
{ font-weight: bold;
}
span.pred-tag
{ float: right;
padding-top: 0.2em;
font-size: 80%;
font-style: italic;
color: #202020;
}
/* Footnotes */
sup.fn { color: blue; text-decoration: underline; }
span.fn-text { display: none; }
sup.fn span {display: none;}
sup:hover span
{ display: block !important;
position: absolute; top: auto; left: auto; width: 80%;
color: #000; background: white;
border: 2px solid;
padding: 5px; margin: 10px; z-index: 100;
font-size: smaller;
}
</STYLE>
</HEAD>
<BODY BGCOLOR="white">
<DIV class="navigate"><A class="nav" href="index.html"><IMG SRC="home.gif" BORDER=0 ALT="Home"></A>
<A class="nav" href="Contents.html"><IMG SRC="index.gif" BORDER=0 ALT="Contents"></A>
<A class="nav" href="DocIndex.html"><IMG SRC="yellow_pages.gif" BORDER=0 ALT="Index"></A>
<A class="nav" href="summary.html"><IMG SRC="info.gif" BORDER=0 ALT="Summary"></A>
<A class="nav" href="chrintro.html"><IMG SRC="prev.gif" BORDER=0 ALT="Previous"></A>
<A class="nav" href="practical.html"><IMG SRC="next.gif" BORDER=0 ALT="Next"></A>
</DIV>
<H2><A NAME="sec:7.2"><SPAN class="sec-nr">7.2</SPAN> <SPAN class="sec-title">Syntax
and Semantics</SPAN></A></H2>
<A NAME="sec:SyntaxAndSemantics"></A>
<H3><A NAME="sec:7.2.1"><SPAN class="sec-nr">7.2.1</SPAN> <SPAN class="sec-title">Syntax</SPAN></A></H3>
The syntax of CHR rules is the following:
<PRE class="code">
rules --> rule, rules.
rules --> [].
rule --> name, actual_rule, pragma, [atom('.')].
name --> atom, [atom('@')].
name --> [].
actual_rule --> simplification_rule.
actual_rule --> propagation_rule.
actual_rule --> simpagation_rule.
simplification_rule --> head, [atom('<=>')], guard, body.
propagation_rule --> head, [atom('==>')], guard, body.
simpagation_rule --> head, [atom('\')], head, [atom('<=>')],
guard, body.
head --> constraints.
constraints --> constraint, constraint_id.
constraints --> constraint, constraint_id, [atom(',')], constraints.
constraint --> compound_term.
constraint_id --> [].
constraint_id --> [atom('#')], variable.
constraint_id --> [atom('#')], [atom('passive')] .
guard --> [].
guard --> goal, [atom('|')].
body --> goal.
pragma --> [].
pragma --> [atom('pragma')], actual_pragmas.
actual_pragmas --> actual_pragma.
actual_pragmas --> actual_pragma, [atom(',')], actual_pragmas.
actual_pragma --> [atom('passive(')], variable, [atom(')')].
</PRE>
<P>Note that the guard of a rule may not contain any goal that binds a
variable in the head of the rule with a non-variable or with another
variable in the head of the rule. It may however bind variables that do
not appear in the head of the rule, e.g. an auxiliary variable
introduced in the guard.
<H3><A NAME="sec:7.2.2"><SPAN class="sec-nr">7.2.2</SPAN> <SPAN class="sec-title">Semantics</SPAN></A></H3>
In this subsection the operational semantics of CHR in Prolog are
presented informally. They do not differ essentially from other CHR
systems.
<P>When a constraint is called, it is considered an active constraint
and the system will try to apply the rules to it. Rules are tried and
executed sequentially in the order they are written.
<P>A rule is conceptually tried for an active constraint in the
following way. The active constraint is matched with a constraint in the
head of the rule. If more constraints appear in the head they are looked
for among the suspended constraints, which are called passive
constraints in this context. If the necessary passive constraints can be
found and all match with the head of the rule and the guard of the rule
succeeds, then the rule is committed and the body of the rule executed.
If not all the necessary passive constraint can be found, the matching
fails or the guard fails, then the body is not executed and the process
of trying and executing simply continues with the following rules. If
for a rule, there are multiple constraints in the head, the active
constraint will try the rule sequentially multiple times, each time
trying to match with another constraint.
<P>This process ends either when the active constraint disappears, i.e. it
is removed by some rule, or after the last rule has been processed. In
the latter case the active constraint becomes suspended.
<P>A suspended constraint is eligible as a passive constraint for an
active constraint. The other way it may interact again with the rules,
is when a variable appearing in the constraint becomes bound to either a
non-variable or another variable involved in one or more constraints. In
that case the constraint is triggered, i.e. it becomes an active
constraint and all the rules are tried.
<P><B>Rule Types</B> There are three different kinds of rules, each with
their specific semantics:
<P>
<UL class="latex">
<LI><I>simplification</I><BR>
The simplification rule removes the constraints in its head and calls
its body.
<P>
<LI><I>propagation</I><BR>
The propagation rule calls its body exactly once for the constraints in
its head.
<P>
<LI><I>simpagation</I><BR>
The simpagation rule removes the constraints in its head after the
<VAR><CODE>\</CODE></VAR> and then calls its body. It is an optimization
of simplification rules of the form: [constraints_1, constraints_2 <=>
constraints_1, body ] Namely, in the simpagation form: [ constraints_1
<CODE>\</CODE>constraints_2 <=> body ] The <VAR>constraints_1</VAR>
constraints are not called in the body.
</UL>
<P><B>Rule Names</B> Naming a rule is optional and has no semantical
meaning. It only functions as documentation for the programmer.
<P><B>Pragmas</B> The semantics of the pragmas are:
<DL class="latex">
<DT><STRONG>passive</STRONG>(<VAR>Identifier</VAR>)</DT>
<DD class="defbody">
The constraint in the head of a rule <VAR>Identifier</VAR> can only
match a passive constraint in that rule. There is an abbreviated syntax
for this pragma. Instead of:
<PRE class="code">
..., c # Id, ... <=> ... pragma passive(Id)
</PRE>
<P>you can also write
<PRE class="code">
..., c # passive, ... <=> ...
</PRE>
<P></DD>
</DL>
<P>Additional pragmas may be released in the future.
<DL class="latex">
<DT class="pubdef"><A NAME="chr_option/2">:- <STRONG>chr_option</STRONG>(<VAR>+Option, +Value</VAR>)</A></DT>
<DD class="defbody">
It is possible to specify options that apply to all the CHR rules in the
module. Options are specified with the <TT>chr_option/2</TT>
declaration:
<PRE class="code">
:- chr_option(Option,Value).
</PRE>
<P>and may appear in the file anywhere after the first constraints
declaration.
<P>Available options are:
<DL class="latex">
<DT><STRONG>check_guard_bindings</STRONG></DT>
<DD class="defbody">
This option controls whether guards should be checked for (illegal)
variable bindings or not. Possible values for this option are <TT>on</TT>,
to enable the checks, and <TT>off</TT>, to disable the checks. If this
option is on, any guard fails when it binds a variable that appears in
the head of the rule. When the option is off (default), the behavior of
a binding in the guard is undefined.</DD>
<DT><STRONG>optimize</STRONG></DT>
<DD class="defbody">
This option controls the degree of optimization. Possible values are <TT>full</TT>,
to enable all available optimizations, and <TT>off</TT> (default), to
disable all optimizations. The default is derived from the SWI-Prolog
flag <A class="flag" href="flags.html#flag:optimise">optimise</A>, where
<CODE>true</CODE> is mapped to <CODE>full</CODE>. Therefore the
command-line option <STRONG>-O</STRONG> provides full CHR optimization.
If optimization is enabled, debugging must be disabled.</DD>
<DT><STRONG>debug</STRONG></DT>
<DD class="defbody">
This options enables or disables the possibility to debug the CHR code.
Possible values are <TT>on</TT> (default) and <TT>off</TT>. See
<A class="sec" href="debugging.html">section 7.4</A> for more details on
debugging. The default is derived from the Prolog flag <A class="flag" href="flags.html#flag:generate_debug_info">generate_debug_info</A>,
which is <CODE>true</CODE> by default. See <STRONG>-nodebug</STRONG>. If
debugging is enabled, optimization must be disabled.
</DD>
</DL>
</DD>
</DL>
<P></BODY></HTML>
|