documentation of memoizing

parent d48680ce
......@@ -27,8 +27,8 @@ Version 0.5, TODO
- Debug features
* Multi threading capabilities (all)
* Tablating (all)
* Circular datastructures (all)
* Tablating (all) DONE
* Circular datastructures (all) DONE
* Refined index lookup datastructure (guile-log)
* Sandboxing (prolog)
* Improved documentation (all)
......@@ -38,12 +38,12 @@ Version 0.5, TODO
* More general functional hashmps (all)
* Ordinary hash maps (all)
* Attributed variables (all) DONE
* corouttines (prolog) PARTLY
* corouttines (prolog) DONE
* Debugging facilities (prolog)
* Better error messages (prolog)
* Better error messages (prolog)
* Better compilation errors (prolog)
* Faster compilation (prolog)
* Improved matcher (prolog)
* Use guile variables when possible (prolog)
* Use guile variables when possible (prolog) DONE
* vectors (prolog)
* structs (prolog)
......@@ -32,6 +32,7 @@ Documentation for the Guile-Log Logic Programming Environment for Guile 2.0 v0.4
* postpone:: To postpone a search.
* dynamics:: catch prompt abort
* dynamic-functions:: Dynamicaly add, remove and execute clauses
* memoizing:: Memoizing and tablating and recursiviness
* parsing:: A parsing framework.
* sed/grep:: Sed and grep functionalities for scheme
* kanren:: Kanren implemented ontop of guile-log
......@@ -45,7 +46,7 @@ Documentation for the Guile-Log Logic Programming Environment for Guile 2.0 v0.4
@chapter Overview
umatch in (logic guile-log umatch) represent the lower level routines
implemented in C code and loaded by that module. A matcher targeted to be
used in code handling the unify variables is defined as well.
used in code handling the unify variables is defined here as well.
@section umatch
@findex umatch
......@@ -1264,6 +1265,70 @@ Finally the last section conserns the ability to compile the dynamic function fo
@findex <dynamic-compile>
@code{G.L. (<dynamic-compile> f ...)}, comiles the dynamic functions @code{f ...} for fast lookup. This ideom takes time and if used freely can cause a high memory consumption.
@node memoizing
@chapter Memoizing
In prolog there is a notion of memoizing datastructures, guile-log elaborates on these datastructures somwhat and also define structures that can work as a sledgehammer in order to handle recursive datastructures, also memoizing somthing that is wrong means that the memoizer in the most general situation needs to backtrack, there is possibility however to cut corners in e.g. algorithms where there is no state storage or where there is no backtracking. The interface is as follows, @code{memo}, @code{memo-rec}, @code{tabling} can all be use as functors in guile log prolog with he help of @code{functorize} wrapper.
@findex memo
@findex memo-rec
@findex rec
@findex rec-once
@findex rec-00
@findex rec-lam
@findex rec-lam-once
@findex rec-lam-00
@code{G.L. (memo fkn arg ...)}
This will assume that fkn only have one result and uses simplified logic to memoize the result and when similar args is available then it will use the old value.
@code{G.L. (memo-rec fkn arg ...)}
The same as above but in stead the function can call itself this means that
@verbatim
(<define> (ff x) (f x))
(<define> (f z) (memo-rec ff x))
@end verbatim
Will not diverge and yield a solution.
@code{G.L. (tabling fkn arg ...)}, as above but it can handle many solutions for the same arguments at the beginning of the funciton, this function also behaves well for recursive definitions and will cut the tree search and yield mostly recursive or rational datastructures. This funciton is not perfect and the same answer might be given multiple times, there is no garantee
@code{Scm (rec f guard action)}
This creates a guile log goal funciton that modifies @code{f}, @code{f} is taking the same vars as the lambda, and make sure to call @code{action} if it sees the an old term that have already been processed action takes a list of all incoming args. The @code{guard} is of the following signature,
@code{G.L. (guard inp s)}, with @code{inp} the list of vars and s the state data that flows with the guile-log program. Rec is a pretty expensive function that behaves well under backtracking and state store and restore.
@code{Scm (rec-once f guard action)}
An optimized verison of @code{rec} for cases when you only take one value of @code{f}
@code{Scm (rec-00 f guard action)}
Does nothing fancy and is therefore fast, assume that there is no backtracking in @code{f} and that it is atomic in the sense that no state store restore is done inside it.
@code{rec-lam, rec-lam-once, rec-lam-00}
The same as the three above but the resulting goal has the signature,
@code{G.L. (*-lam-* action arg ...)}, with @code{action} beeing executed just like the overall @code{action} in the mother functor.
@findex rec-action
@findex rec-action00
@code{G.L. (rec-action action x)}
Will execute @code{action} in case a term show up a second time in scanning the datastructure @code{x}.
@code{G.L. (rec-action00 action x)}
Will execute @code{action} in case a term show up a second time in scanning the datastructure @code{x}. This assume no backtracking in @code{action}.
@findex rec=
@findex rec==
@findex recursive
@code{G.L. (rec= X Y)} , a recursive safe unify procedure.
@code{G.L. (rec== X Y)}, a recursive safe eqvivalence procedure.
@code{(recursive f arg ...)}, this functor can be used to modify f so that it
will do all of it's work using recursive safe unifyeres etc. This can be used as a functor modifyier in prolog.
@node parsing
@chapter Parsing
......
......@@ -56,7 +56,7 @@ Previous: <a href="garbage_002dcollect.html#garbage_002dcollect" accesskey="p" r
</div>
<hr>
<a name="Index-of-the-guile_002dlog-api"></a>
<h2 class="chapter">12 Index of the guile-log api</h2>
<h2 class="chapter">13 Index of the guile-log api</h2>
<a name="Index-1"></a>
<h2 class="unnumbered">Index</h2>
......@@ -389,6 +389,8 @@ Previous: <a href="garbage_002dcollect.html#garbage_002dcollect" accesskey="p" r
<tr><th><a name="Index_fn_letter-M">M</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="expressions.html#index-make_002dopdata"><code>make-opdata</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="expressions.html#expressions">expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="prolog-hash.html#index-make_005fvhash"><code>make_vhash</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="prolog-hash.html#prolog-hash">prolog hash</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-memo"><code>memo</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-memo_002drec"><code>memo-rec</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="expressions.html#index-mk_002doperator_002dexpression"><code>mk-operator-expression</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="expressions.html#expressions">expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="parser-combinators.html#index-mk_002dtoken"><code>mk-token</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="parser-combinators.html#parser-combinators">parser combinators</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
......@@ -423,6 +425,17 @@ Previous: <a href="garbage_002dcollect.html#garbage_002dcollect" accesskey="p" r
<tr><td></td><td valign="top"><a href="kanren.html#index-query"><code>query</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="kanren.html#kanren">kanren</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Index_fn_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec"><code>rec</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_002d00"><code>rec-00</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_002daction"><code>rec-action</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_002daction00"><code>rec-action00</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_002dlam"><code>rec-lam</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_002dlam_002d00"><code>rec-lam-00</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_002dlam_002donce"><code>rec-lam-once</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_002donce"><code>rec-once</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_003d"><code>rec=</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-rec_003d_003d"><code>rec==</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="memoizing.html#index-recursive"><code>recursive</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="memoizing.html#memoizing">memoizing</a></td></tr>
<tr><td></td><td valign="top"><a href="kanren.html#index-reify"><code>reify</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="kanren.html#kanren">kanren</a></td></tr>
<tr><td></td><td valign="top"><a href="kanren.html#index-relation"><code>relation</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="kanren.html#kanren">kanren</a></td></tr>
<tr><td></td><td valign="top"><a href="expressions.html#index-rem_002doperator"><code>rem-operator</code></a>:</td><td>&nbsp;</td><td valign="top"><a href="expressions.html#expressions">expressions</a></td></tr>
......
......@@ -15,7 +15,7 @@ Copyright (C) 2012 Stefan Israelsson Tampe -->
<link href="index.html#Top" rel="start" title="Top">
<link href="Index.html#Index" rel="index" title="Index">
<link href="index.html#Top" rel="up" title="Top">
<link href="parsing.html#parsing" rel="next" title="parsing">
<link href="memoizing.html#memoizing" rel="next" title="memoizing">
<link href="dynamics.html#dynamics" rel="prev" title="dynamics">
<style type="text/css">
<!--
......@@ -53,7 +53,7 @@ ul.no-bullet {list-style: none}
<a name="dynamic_002dfunctions"></a>
<div class="header">
<p>
Next: <a href="parsing.html#parsing" accesskey="n" rel="next">parsing</a>, Previous: <a href="dynamics.html#dynamics" accesskey="p" rel="prev">dynamics</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
Next: <a href="memoizing.html#memoizing" accesskey="n" rel="next">memoizing</a>, Previous: <a href="dynamics.html#dynamics" accesskey="p" rel="prev">dynamics</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Dynamic-functions"></a>
......@@ -100,11 +100,10 @@ downside is that they posses problem w.r.t. leaking data and therefor the next i
<a name="index-_003cdynamic_002dcompile_003e"></a>
<p><code>G.L. (&lt;dynamic-compile&gt; f ...)</code>, comiles the dynamic functions <code>f ...</code> for fast lookup. This ideom takes time and if used freely can cause a high memory consumption.
</p>
<hr>
<div class="header">
<p>
Next: <a href="parsing.html#parsing" accesskey="n" rel="next">parsing</a>, Previous: <a href="dynamics.html#dynamics" accesskey="p" rel="prev">dynamics</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
Next: <a href="memoizing.html#memoizing" accesskey="n" rel="next">memoizing</a>, Previous: <a href="dynamics.html#dynamics" accesskey="p" rel="prev">dynamics</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
......
......@@ -57,11 +57,11 @@ Previous: <a href="parser-combinators.html#parser-combinators" accesskey="p" rel
</div>
<hr>
<a name="Expressions"></a>
<h3 class="section">7.3 Expressions</h3>
<h3 class="section">8.3 Expressions</h3>
<p>This is a configureable expression parser that can be used for prolog parsing as well as parsing C and C++ expressions. To note is that the data is functionally updated and hence one can store the state at will and later reinstate the parser. The parser ideom is a direct translation of the commonly described prolog parser written in prolog to guile-log. It is then extended to allow ternial operators like <code>?</code> in c as well. To use it load the module <code>(logic guile-log parsing operator-parser)</code>
</p>
<a name="Api-2"></a>
<h4 class="subsection">7.3.1 Api</h4>
<h4 class="subsection">8.3.1 Api</h4>
<a name="index-make_002dopdata"></a>
<p><code>(make-opdata)</code>, initiates a datastructure to containe needed operator data. The result is a fluid pointing to a functional datastructure.
</p>
......
......@@ -57,7 +57,7 @@ Next: <a href="Index.html#Index" accesskey="n" rel="next">Index</a>, Previous: <
</div>
<hr>
<a name="Prolog-1"></a>
<h2 class="chapter">11 Prolog</h2>
<h2 class="chapter">12 Prolog</h2>
<p>Guile log sports full garbage collection of logical variables which makes it suitable to run server like prolog code. It is experimental but working. Unfourtunately the bdw-gc that guile uses does not allow this to work effectively and hence you need to download and replace the standard bdw-gc with a modified version of it. You may find it at
</p>
......
......@@ -77,11 +77,13 @@ Next: <a href="umatch.html#umatch" accesskey="n" rel="next">umatch</a>, Up: <a h
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="dynamic_002dfunctions.html#dynamic_002dfunctions" accesskey="6">dynamic-functions</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Dynamicaly add, remove and execute clauses
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="parsing.html#parsing" accesskey="7">parsing</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A parsing framework.
<tr><td align="left" valign="top">&bull; <a href="memoizing.html#memoizing" accesskey="7">memoizing</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Memoizing and tablating and recursiviness
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="sed_002fgrep.html#sed_002fgrep" accesskey="8">sed/grep</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Sed and grep functionalities for scheme
<tr><td align="left" valign="top">&bull; <a href="parsing.html#parsing" accesskey="8">parsing</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A parsing framework.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="kanren.html#kanren" accesskey="9">kanren</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Kanren implemented ontop of guile-log
<tr><td align="left" valign="top">&bull; <a href="sed_002fgrep.html#sed_002fgrep" accesskey="9">sed/grep</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Sed and grep functionalities for scheme
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="kanren.html#kanren">kanren</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Kanren implemented ontop of guile-log
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="prolog.html#prolog">prolog</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">iso-prolog
</td></tr>
......
......@@ -57,13 +57,13 @@ Next: <a href="prolog.html#prolog" accesskey="n" rel="next">prolog</a>, Previous
</div>
<hr>
<a name="Kanren"></a>
<h2 class="chapter">9 Kanren</h2>
<h2 class="chapter">10 Kanren</h2>
<p>Almost all of the kanren interface is implemented ontop of guile-log to use it import <code>logic guile-log kanren</code>. One could say that the kanren interface is the functional sister to guile-log which is more a macro framework as such guile-log is about 2x faster the kanren, but kanren has more beutifull semantics.
E.g. the kanren operation maps function arguments to functions. The kanren interface is divided into two categories of functionals, facts and relations. One combine facts into relations. The main difference is that fact functions have standardized arguments and relations have customized arguments. Also conversely evaluating the relation will return back a fact.
</p>
<a name="The-fact-building-blocks"></a>
<h3 class="section">9.1 The fact building blocks</h3>
<h3 class="section">10.1 The fact building blocks</h3>
<a name="index-succeed"></a>
<a name="index-fail"></a>
<a name="index-sfail"></a>
......@@ -134,7 +134,7 @@ skipp multiples of similar sucesses e.g. if <code>(all f1 f2)</code> is a succes
<p><code>_</code>, produces a fress new logical variable in it&rsquo;s place.
</p>
<a name="relations"></a>
<h3 class="section">9.2 relations</h3>
<h3 class="section">10.2 relations</h3>
<a name="index-relation"></a>
<a name="index-fact"></a>
<a name="index-extend_002drelation"></a>
......@@ -202,7 +202,7 @@ variables <code>id ...</code>. E.g.
</p>
<a name="Queries"></a>
<h3 class="section">9.3 Queries</h3>
<h3 class="section">10.3 Queries</h3>
<a name="index-query"></a>
<a name="index-solve"></a>
......@@ -215,7 +215,7 @@ variables <code>id ...</code>. E.g.
<p><code>(solution (v ...) g ...</code>, This is the same as <code>(solve 1 (v ...) g ...)</code>.
</p>
<a name="Misc"></a>
<h3 class="section">9.4 Misc</h3>
<h3 class="section">10.4 Misc</h3>
<a name="index-trace_002dvars"></a>
<a name="index-partially_002deval_002dsgl"></a>
......@@ -224,7 +224,7 @@ variables <code>id ...</code>. E.g.
<p><code>partially-eval-sgl</code>, not implemented, because guile-log is also directed towards stacks and assq lists and hence usually uses another kind of implementation for the interleaving constructs.
</p>
<a name="Examples"></a>
<h3 class="section">9.5 Examples</h3>
<h3 class="section">10.5 Examples</h3>
<pre class="verbatim">Example 1, any-union,
(let* ((fact1 (fact () 'x1 'y1))
(fact2 (fact () 'x2 'y2))
......
......@@ -57,11 +57,11 @@ Next: <a href="expressions.html#expressions" accesskey="n" rel="next">expression
</div>
<hr>
<a name="Parser-Combinators"></a>
<h3 class="section">7.2 Parser Combinators</h3>
<h3 class="section">8.2 Parser Combinators</h3>
<p>The combinators are basic elements that you get from the module <code>(logic guile-log parser)</code>. To note here is with these we define elements to do parsing in a &ldquo;functional&rdquo; way together with som utilities to memoize sections and produce tokens. Tokens are more interned scheme data then the standard way of matching that is lightweight and just represent sequences of the incoming chars. They are also cheap to backtrack over but will put a demand on the supply of prolog variables.
</p>
<a name="higher-order-elements"></a>
<h4 class="subsection">7.2.1 higher order elements</h4>
<h4 class="subsection">8.2.1 higher order elements</h4>
<a name="index-f_002dand"></a>
<a name="index-f_002dand_0021"></a>
<a name="index-f_002dand_0021_0021"></a>
......@@ -91,7 +91,7 @@ Next: <a href="expressions.html#expressions" accesskey="n" rel="next">expression
<p><code>(fn f n m)</code>, matches <code>f</code> n to m times
</p>
<a name="Basic-parser-functions"></a>
<h4 class="subsection">7.2.2 Basic parser functions</h4>
<h4 class="subsection">8.2.2 Basic parser functions</h4>
<a name="index-f_002dtag"></a>
<a name="index-f_002dtag_0021"></a>
<a name="index-f_002dtag_002dpr"></a>
......@@ -120,7 +120,7 @@ Next: <a href="expressions.html#expressions" accesskey="n" rel="next">expression
<a name="utilities"></a>
<h4 class="subsection">7.2.3 utilities</h4>
<h4 class="subsection">8.2.3 utilities</h4>
<a name="index-p_002dfreeze"></a>
<p><code>(p-freeze tok f mk)</code> This will freeze the interpretation of the comming characters according to the parser function <code>f</code> as token <code>tok</code>. Using backtracking, one can get into the unfourtunate stage of reparsing things over and over again. WIth p-freeze we will memoize the reseult and the second time we try to parse the token at the same position we will just use the memoized data. this is how we tokenize and gives the guile-log parsing system a slower tokenizer on one hand, then traditional tokenizers, but on the other hand allows far more advanced tokens to be builed e.g. tokenize a parenthesied expression in C. <code>mk</code> is a function whos purpose is to construct that value that should be memoized it has the signature
</p>
......
......@@ -16,7 +16,7 @@ Copyright (C) 2012 Stefan Israelsson Tampe -->
<link href="Index.html#Index" rel="index" title="Index">
<link href="index.html#Top" rel="up" title="Top">
<link href="stream-ideom.html#stream-ideom" rel="next" title="stream ideom">
<link href="dynamic_002dfunctions.html#dynamic_002dfunctions" rel="prev" title="dynamic-functions">
<link href="memoizing.html#memoizing" rel="prev" title="memoizing">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
......@@ -53,11 +53,11 @@ ul.no-bullet {list-style: none}
<a name="parsing"></a>
<div class="header">
<p>
Next: <a href="sed_002fgrep.html#sed_002fgrep" accesskey="n" rel="next">sed/grep</a>, Previous: <a href="dynamic_002dfunctions.html#dynamic_002dfunctions" accesskey="p" rel="prev">dynamic-functions</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
Next: <a href="sed_002fgrep.html#sed_002fgrep" accesskey="n" rel="next">sed/grep</a>, Previous: <a href="memoizing.html#memoizing" accesskey="p" rel="prev">memoizing</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Parsing"></a>
<h2 class="chapter">7 Parsing</h2>
<h2 class="chapter">8 Parsing</h2>
<p>Prolog has historically been used for setting up parsers for various languages and has an extensible expression parser where one congigure the operator handling. We continue in this tradition to produce elements to do backtracking enabled parsing for guile. With this, one can explore the new interesting constructs in guile-log to enable new features with respect to parsing.
</p>
<p>Generally in guile-log a parser is a function that follows a certain call semantics. It is a guile log function e.g. it takes the standard arguments <code>S P CC</code>. But ontop of this it takes <code>X XL N M</code> e.g. current char on line (<code>X</code>), current line in stream of lines (<code>XL</code>), current line column (<code>N</code>) and current line number (<code>M</code>). Typically in code these elements are hidden in return values as calling signatures and hence the resulting code is less littered with standard ideoms and tons of variables. This design allows the programmer to easier spot errors and also produce fewer of them and we belive that it is a boon for productivity when writing parsers. Ontop of this semantics an extra output stream field in both imputt and output may be supplied e.g. the tool needed to produce a syntax tree. Code look typically like this, when using this tool to produce a parser function
......@@ -91,7 +91,7 @@ Next: <a href="sed_002fgrep.html#sed_002fgrep" accesskey="n" rel="next">sed/grep
<hr>
<div class="header">
<p>
Next: <a href="sed_002fgrep.html#sed_002fgrep" accesskey="n" rel="next">sed/grep</a>, Previous: <a href="dynamic_002dfunctions.html#dynamic_002dfunctions" accesskey="p" rel="prev">dynamic-functions</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
Next: <a href="sed_002fgrep.html#sed_002fgrep" accesskey="n" rel="next">sed/grep</a>, Previous: <a href="memoizing.html#memoizing" accesskey="p" rel="prev">memoizing</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
......
......@@ -57,7 +57,7 @@ Next: <a href="garbage_002dcollect.html#garbage_002dcollect" accesskey="n" rel="
</div>
<hr>
<a name="Prolog"></a>
<h2 class="chapter">10 Prolog</h2>
<h2 class="chapter">11 Prolog</h2>
<p>Guile log also sports an iso-prolog interface as a logic programming interface besides kanren. The interface is pretty complete at this point appart a few points that have not yet been resolved but sure it is currently alpha software and help is very very much appriciated. With this most programs written in iso prolog should probably work. The intention is to enhance this interface so that the bulk of already written prolog programs should be able to run on guile. We will also add the fetures unique to guile-log and hence enhance the prolog experience. Featurewise guile-log prolog is taking over many properties of scheme like closures, continuations, delimeted continuations, the interleaving constructs of kanren and a delicate system to treat dynamic objects like dynamic functions, dynamic hashes and a library to tell how you want the dynamism to work at a fine grained level.
</p>
<table class="menu" border="0" cellspacing="0">
......
......@@ -57,11 +57,11 @@ Next: <a href="kanren.html#kanren" accesskey="n" rel="next">kanren</a>, Previous
</div>
<hr>
<a name="Sed_002fgrep-overview"></a>
<h2 class="chapter">8 Sed/grep overview</h2>
<h2 class="chapter">9 Sed/grep overview</h2>
<p>To overengineer and test out the framework a simple grep and sed utility has been designed. It knows about scheme and can locate and translate scheme files as well as having traditional grep/sed funcitonality. The main interface is in the module <code>(logic guile-log grep)</code>.
</p>
<a name="Api-3"></a>
<h3 class="section">8.1 Api</h3>
<h3 class="section">9.1 Api</h3>
<p><code>(grep match code #:key (a 0) (b 0) (c 0))</code>, this will evaluate <code>code</code> in a separate thread and capture standard output and only print what the parser function <code>match</code> matches. <code>a,b,c</code> defines an interval <code>[min(-b,-c),max(a,c)]</code> around the matched line which is printed.
</p>
<p><code>(sed match code)</code>, will print everything but if match matches, it&rsquo;s output will be printed instead by the matcher, e.g. use the pr versions of the parser combinators for printing matches.
......@@ -71,7 +71,7 @@ Next: <a href="kanren.html#kanren" accesskey="n" rel="next">kanren</a>, Previous
<p><code>(par-sed match code #:key (str q-false) (com q-false))</code>, This is a sed utility that knows about scheme.
</p>
<a name="The-scheme-matcher_002e"></a>
<h3 class="section">8.2 The scheme matcher.</h3>
<h3 class="section">9.2 The scheme matcher.</h3>
<p>In order to translate scheme code we have a nice little monster framework to to the grunt work. You may use it by importing (logic guile-log parsing sch-match).
To use this one need to know about how syntax-parse works. We only support a subset of the syntax-parse interface, namlely the directives <code>~and ~or ~not ~var _)</code> added to this we make use of ice-9 match notation for symbols.
</p>
......@@ -90,11 +90,11 @@ This works just as with <code>define-splicing-syntax-class</code> in syntax-pars
<p><code>(scm-match pat)</code>, use this as a matcher in par-grep, but with the syntax-parse pattern interface to define a match.
</p>
<a name="Building-the-result_002e"></a>
<h3 class="section">8.3 Building the result.</h3>
<h3 class="section">9.3 Building the result.</h3>
<p>The philosophy is to treat the sed translation as a special syntax transform. A variable <code>x</code> in the pattern will produce three sub matches, <code>x.l,x.it.x.r</code>. e.g. left whitespace, sexp, right whitespace. By matching <code>#(l it r)</code> l will be left whitespace, it the sexp and r the right whitespace, and this is how you define the output as well in order to surround an element with whitespace.
</p>
<a name="Example-2"></a>
<h3 class="section">8.4 Example</h3>
<h3 class="section">9.4 Example</h3>
<p>This is an example how one may define a sed translator that swaps the meaning of variable and value in a let form and preserving whitespace as much as possible.
</p>
<pre class="verbatim">(define-match-class swap
......
......@@ -57,7 +57,7 @@ Next: <a href="parser-combinators.html#parser-combinators" accesskey="n" rel="ne
</div>
<hr>
<a name="Stream-ideom-api"></a>
<h3 class="section">7.1 Stream ideom api</h3>
<h3 class="section">8.1 Stream ideom api</h3>
<a name="index-define_002dguile_002dlog_002dparser"></a>
<p>There is a little framework in guile-log imported with <code>(logic guile-log)</code> that enables the setup of syntactic sugar for streams. The api is
</p>
......@@ -70,7 +70,7 @@ Next: <a href="parser-combinators.html#parser-combinators" accesskey="n" rel="ne
<p><code>xx</code> is used to capture the return of a subexpression like in the example below. It cannot be used to call parser funcitons.
</p>
<a name="Example-1"></a>
<h4 class="subsection">7.1.1 Example</h4>
<h4 class="subsection">8.1.1 Example</h4>
<p>The parsing framwork is using
</p>
<pre class="verbatim">(define-guile-log-parser-tool (&lt;p-lambda&gt; (X XL N M)) &lt;p-define&gt; .. xx &lt;p-cc&gt;)
......
......@@ -60,7 +60,7 @@ Next: <a href="guile_002dlog.html#guile_002dlog" accesskey="n" rel="next">guile-
<h2 class="chapter">1 Overview</h2>
<p>umatch in (logic guile-log umatch) represent the lower level routines
implemented in C code and loaded by that module. A matcher targeted to be
used in code handling the unify variables is defined as well.
used in code handling the unify variables is defined here as well.
</p>
<a name="umatch-1"></a>
<h3 class="section">1.1 umatch</h3>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment