/usr/share/doc/racket/datalog/datalog.html is in racket-doc 6.7-3.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>1 Datalog Module Language</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_0");">▼</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">Datalog:<span class="mywbr"> </span> Deductive Database Programming</a></td></tr></table></div><div class="tocviewsublistonly" style="display: block;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1 </td><td><a href="" class="tocviewselflink" data-pltdoc="x">Datalog Module Language</a></td></tr><tr><td align="right">2 </td><td><a href="Tutorial.html" class="tocviewlink" data-pltdoc="x">Tutorial</a></td></tr><tr><td align="right">3 </td><td><a href="Parenthetical_Datalog_Module_Language.html" class="tocviewlink" data-pltdoc="x">Parenthetical Datalog Module Language</a></td></tr><tr><td align="right">4 </td><td><a href="interop.html" class="tocviewlink" data-pltdoc="x">Racket Interoperability</a></td></tr><tr><td align="right">5 </td><td><a href="Acknowledgments.html" class="tocviewlink" data-pltdoc="x">Acknowledgments</a></td></tr></table></div></div></div></div><div class="maincolumn"><div class="main"><div class="navsettop"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.7", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.7");">top</a></span><span class="navright"> <a href="index.html" title="backward to "Datalog: Deductive Database Programming"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "Datalog: Deductive Database Programming"" data-pltdoc="x">up</a> <a href="Tutorial.html" title="forward to "2 Tutorial"" data-pltdoc="x">next →</a></span> </div><h3 x-source-module="(lib "datalog/scribblings/datalog.scrbl")" x-source-pkg="datalog" x-part-tag=""datalog"">1<tt> </tt><a name="(part._datalog)"></a><a name="(mod-path._datalog/lang/reader)"></a>Datalog Module Language</h3><p><table cellspacing="0" cellpadding="0" class="defmodule"><tr><td align="left"><span class="hspace"> </span><a href="https://download.racket-lang.org/docs/6.7/html/local-redirect/index.html?doc=guide&rel=Module_Syntax.html%23%2528part._hash-lang%2529&version=6.7" class="RktModLink Sq" data-pltdoc="x"><span class="RktMod">#lang</span></a><span class="hspace"> </span><a href="interop.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">datalog</span></a></td><td align="right"><span class="RpackageSpec"><span class="Smaller"> package:</span> <span class="stt">datalog</span></span></td></tr></table></p><p>In Datalog input, whitespace characters are ignored except when they separate adjacent tokens or when they occur in strings.
Comments are also considered to be whitespace. The character <span class="RktInBG"><span class="hspace"></span><span class="RktIn">%</span><span class="hspace"></span></span> introduces a comment, which extends to the next line break.
Comments do not occur inside strings.</p><p>A variable is a sequence of Unicode "Uppercase" and "Lowercase" letters, digits, and the underscore character. A variable must begin with a Unicode "Uppercase" letter.</p><p>An identifier is a sequence of printing characters that does not contain any of the following characters: <span class="RktInBG"><span class="hspace"></span><span class="RktIn">(</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">`</span><span class="hspace"></span></span>,
<span class="RktInBG"><span class="hspace"></span><span class="RktIn">'</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">)</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">=</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">:</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">.</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">~</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">?</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">"</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">%</span><span class="hspace"></span></span>, and space.
An identifier must not begin with a Latin capital letter. Note that the characters that start punctuation are forbidden in identifiers,
but the hyphen character is allowed.</p><p>A string is a sequence of characters enclosed in double quotes. Characters other than double quote, newline, and backslash may be directly
included in a string. The remaining characters may be specified using escape characters, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">\"</span><span class="hspace"></span></span>, <span class="RktInBG"><span class="hspace"></span><span class="RktIn">\</span><span class="hspace"> </span></span>, and
<span class="RktInBG"><span class="hspace"></span><span class="RktIn">\\</span><span class="hspace"></span></span> respectively.</p><p><div class="SIntrapara">A literal, is a predicate symbol followed by an optional parenthesized list of comma separated terms. A predicate symbol is either an identifier
or a string. A term is either a variable or a constant. As with predicate symbols, a constant is either an identifier or a string. As a special case,
two terms separated by <span class="RktInBG"><span class="hspace"></span><span class="RktIn">=</span><span class="hspace"></span></span> (<span class="RktInBG"><span class="hspace"></span><span class="RktIn">!=</span><span class="hspace"></span></span>) is a literal for the equality (inequality) predicate.
The following are literals:
</div><div class="SIntrapara"><table cellspacing="0" cellpadding="0"><tr><td><p><span class="hspace"> </span><span class="stt">parent(john, douglas)</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt">zero-arity-literal</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt">"="(3,3)</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt">""(-0-0-0,&&&,***,"\00")</span></p></td></tr></table></div></p><p>A clause is a head literal followed by an optional body. A body is a comma separated list of literals. A clause without a body is called a <a name="(tech._fact)"></a><span style="font-style: italic">fact</span>,
and a rule when it has one. The punctuation <span class="RktInBG"><span class="hspace"></span><span class="RktIn">:-</span><span class="hspace"></span></span> separates the head of a rule from its body. A clause is safe if every variable in its head
occurs in some literal in its body. The following are safe clauses:</p><p><table cellspacing="0" cellpadding="0"><tr><td><p><span class="hspace"> </span><span class="stt">parent(john, douglas)</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt">ancestor(A, B) :-</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt"></span><span class="hspace"> </span><span class="stt">parent(A, B)</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt">ancestor(A, B) :-</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt"></span><span class="hspace"> </span><span class="stt">parent(A, C),</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt"></span><span class="hspace"> </span><span class="stt">ancestor(C, B)</span></p></td></tr></table></p><p>A program is a sequence of zero or more statements. A statement is an assertion, a retraction, or a query. An assertion is a clause followed by
a period, and it adds the clause to the database if it is safe. A retraction is a clause followed by a tilde, and it removes the clause from
the database. A query is a literal followed by a question mark.</p><p>The following BNF describes the syntax of Datalog.</p><p><table cellspacing="0" cellpadding="0"><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">program</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">statement</span>›</span><span class="sroman">*</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">statement</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">assertion</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">retraction</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">query</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">assertion</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">clause</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">.</span><span class="hspace"></span></span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">retraction</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">clause</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">~</span><span class="hspace"></span></span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">query</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">literal</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">?</span><span class="hspace"></span></span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">clause</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">literal</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">:-</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">body</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">literal</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">body</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">literal</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">,</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">body</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">literal</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">literal</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">predicate-sym</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">(</span><span class="hspace"></span></span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">)</span><span class="hspace"></span></span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">predicate-sym</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">(</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">terms</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">)</span><span class="hspace"></span></span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">predicate-sym</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">term</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">=</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">term</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">term</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">!=</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">term</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">predicate-sym</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">IDENTIFIER</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">STRING</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">terms</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">term</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">term</span>›</span><span class="hspace"> </span><span class="RktInBG"><span class="hspace"></span><span class="RktIn">,</span><span class="hspace"></span></span><span class="hspace"> </span><span class="sroman">‹<span style="font-style: italic">terms</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">term</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">VARIABLE</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">constant</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">constant</span>›</span></p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span>::=<span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">IDENTIFIER</span>›</span></p></td></tr><tr><td valign="baseline"><p><span class="hspace"> </span></p></td><td valign="baseline"><p> </p></td><td valign="baseline"><p><span class="stt"><span class="hspace"> </span><span class="hspace"> </span>|<span class="hspace"> </span><span class="hspace"> </span></span></p></td><td valign="baseline"><p><span class="sroman">‹<span style="font-style: italic">STRING</span>›</span></p></td></tr></table></p><p>The effect of running a Datalog program is to modify the database as directed
by its statements, and then to return the literals designated by the query.
The modified database is provided as <span class="RktSym">theory</span>.</p><p>The following is a program:</p><p><table cellspacing="0" cellpadding="0"><tr><td><p><span class="hspace"> </span><span class="stt"></span><span class="hspace"> </span><span class="stt">#lang datalog</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt"></span><span class="hspace"> </span><span class="stt">edge(a, b). edge(b, c). edge(c, d). edge(d, a).</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt"></span><span class="hspace"> </span><span class="stt">path(X, Y) :- edge(X, Y).</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt"></span><span class="hspace"> </span><span class="stt">path(X, Y) :- edge(X, Z), path(Z, Y).</span></p></td></tr><tr><td><p><span class="hspace"> </span><span class="stt"></span><span class="hspace"> </span><span class="stt">path(X, Y)?</span></p></td></tr></table></p><p>The Datalog REPL accepts new statements that are executed as if they were in the original program text.</p><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.7", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.7");">top</a></span><span class="navright"> <a href="index.html" title="backward to "Datalog: Deductive Database Programming"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "Datalog: Deductive Database Programming"" data-pltdoc="x">up</a> <a href="Tutorial.html" title="forward to "2 Tutorial"" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html>
|