Started documentating + documentation cleanup

parent f5f3509b
This diff is collapsed.
This diff is collapsed.
......@@ -35,15 +35,15 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">9 Overview</h2>
<h2 class="chapter">3 Acumulators/generators</h2>
<p>In the guile-log chapter we defined the basic framework to fold a sequence of solutions into a variable. With this we can support e.g prolog's bagof and similar constructs. In the module <code>(guile-log logic collects)</code>, we have defined a few specialisations of the fold operator in order to standardize these common abstractions.
<h2 class="chapter">10 Acumulators API</h2>
<h3 class="section">3.1 Acumulators API</h3>
<p>To explain the Api we have a <code>gl-thunk</code>, e.g. a guile-log lambda with zero arguments. <code>it</code>, will be the pattern to store. when it successes typically this variable will be copied and added to the resulting data structure which is <code>list, sum, ...</code>. There is a possibility to keep some elements fixed and this is the <code>-2</code> forms with the variable <code>fixed</code> naming the variable that needs to be fixated. e.g. first all solutions for the first found representation of the variable <code>fixed</code> will be found and added, then the then all solutions with the next found variant of the <code>fixed</code> will be used and so on, very much like how bagof in prolog is working. The <code>-step</code> versions of the acumulators will produce produce all the intermediate acumulator solutions.
<p><a name="index-g_t_003ccollect_003e-151"></a><a name="index-g_t_003ccollect_002d2_003e-152"></a><a name="index-g_t_003ccollect_002dstep_003e-153"></a><a name="index-g_t_003ccollect_002dstep_002d2_003e-154"></a>The following forms will cons all solutions to a list e.g. prodice lists in
<p><a name="index-g_t_003ccollect_003e-143"></a><a name="index-g_t_003ccollect_002d2_003e-144"></a><a name="index-g_t_003ccollect_002dstep_003e-145"></a><a name="index-g_t_003ccollect_002dstep_002d2_003e-146"></a>The following forms will cons all solutions to a list e.g. prodice lists in
reverse order.
<p><code>G.L. (&lt;collect&gt; gl-thunk it list)</code>
......@@ -56,7 +56,7 @@ reverse order.
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;
<p><a name="index-g_t_003csum_003e-155"></a><a name="index-g_t_003csum_002d2_003e-156"></a><a name="index-g_t_003csum_002dstep_003e-157"></a><a name="index-g_t_003csum_002dstep_002d2_003e-158"></a>The following forms will sum all solutions.
<p><a name="index-g_t_003csum_003e-147"></a><a name="index-g_t_003csum_002d2_003e-148"></a><a name="index-g_t_003csum_002dstep_003e-149"></a><a name="index-g_t_003csum_002dstep_002d2_003e-150"></a>The following forms will sum all solutions.
<p><code>G.L. (&lt;collect&gt; gl-thunk it sum)</code>
......@@ -68,7 +68,7 @@ reverse order.
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
<p><a name="index-g_t_003cprod_003e-159"></a><a name="index-g_t_003cprod_002d2_003e-160"></a><a name="index-g_t_003cprod_002dstep_003e-161"></a><a name="index-g_t_003cprod_002dstep_002d2_003e-162"></a>The following forms will take the product of all solutins
<p><a name="index-g_t_003cprod_003e-151"></a><a name="index-g_t_003cprod_002d2_003e-152"></a><a name="index-g_t_003cprod_002dstep_003e-153"></a><a name="index-g_t_003cprod_002dstep_002d2_003e-154"></a>The following forms will take the product of all solutins
<p><code>G.L. (&lt;collect&gt; gl-thunk it prod)</code>
......@@ -80,7 +80,7 @@ reverse order.
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;
<p><a name="index-g_t_003cmax_003e-163"></a><a name="index-g_t_003cmax_002d2_003e-164"></a><a name="index-g_t_003cmax_002dstep_003e-165"></a><a name="index-g_t_003cmax_002dstep_002d2_003e-166"></a>The following forms will take the max of all solutions.
<p><a name="index-g_t_003cmax_003e-155"></a><a name="index-g_t_003cmax_002d2_003e-156"></a><a name="index-g_t_003cmax_002dstep_003e-157"></a><a name="index-g_t_003cmax_002dstep_002d2_003e-158"></a>The following forms will take the max of all solutions.
<p><code>G.L. (&lt;max&gt; gl-thunk it max)</code>
......@@ -92,7 +92,7 @@ reverse order.
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;
<p><a name="index-g_t_003cmin_003e-167"></a><a name="index-g_t_003cmin_002d2_003e-168"></a><a name="index-g_t_003cmin_002dstep_003e-169"></a><a name="index-g_t_003cmin_002dstep_002d2_003e-170"></a>The following forms will take the max of all solutions.
<p><a name="index-g_t_003cmin_003e-159"></a><a name="index-g_t_003cmin_002d2_003e-160"></a><a name="index-g_t_003cmin_002dstep_003e-161"></a><a name="index-g_t_003cmin_002dstep_002d2_003e-162"></a>The following forms will take the max of all solutions.
<p><code>G.L. (&lt;min&gt; gl-thunk it min)</code>
......@@ -104,7 +104,7 @@ reverse order.
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;
<p><a name="index-g_t_003csoland_003e-171"></a><a name="index-g_t_003csoland_002d2_003e-172"></a><a name="index-g_t_003csoland_002dstep_003e-173"></a><a name="index-g_t_003csoland_002dstep_002d2_003e-174"></a>The following forms will take the and of all operations returning the last one
<p><a name="index-g_t_003csoland_003e-163"></a><a name="index-g_t_003csoland_002d2_003e-164"></a><a name="index-g_t_003csoland_002dstep_003e-165"></a><a name="index-g_t_003csoland_002dstep_002d2_003e-166"></a>The following forms will take the and of all operations returning the last one
as a solution.
<p><code>G.L. (&lt;soland&gt; gl-thunk it and)</code>
......@@ -117,7 +117,7 @@ as a solution.
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;
<p><a name="index-g_t_003csolor_003e-175"></a><a name="index-g_t_003csolor_002d2_003e-176"></a><a name="index-g_t_003csolor_002dstep_003e-177"></a><a name="index-g_t_003csolor_002dstep_002d2_003e-178"></a>The following forms will take the or of all operations returning the first solution.
<p><a name="index-g_t_003csolor_003e-167"></a><a name="index-g_t_003csolor_002d2_003e-168"></a><a name="index-g_t_003csolor_002dstep_003e-169"></a><a name="index-g_t_003csolor_002dstep_002d2_003e-170"></a>The following forms will take the or of all operations returning the first solution.
<p><code>G.L. (&lt;solor&gt; gl-thunk it or)</code>
......@@ -127,7 +127,7 @@ as a solution.
<p><code>G.L. (&lt;solor-step-2&gt; gl-thunk it fixed or)</code>
<h2 class="chapter">11 Local Non backtracking Genrators API</h2>
<h3 class="section">3.2 Local Non backtracking Genrators API</h3>
<p>This tool is found directly in the module <code>(logic guile-log)</code>,
......
......@@ -34,11 +34,11 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">14 database</h2>
<h2 class="chapter">13 Database</h2>
<p>Anything prolog like means that we need some kind of database for matching. And one such tool is included in guile-log. This is not a dynamic databas but one that we only can add elements and then compile and use it for lookup. It has some optimizations in it to be effective at looking the elements up still maintaining the introduced orders.
<h3 class="section">14.1 Api</h3>
<h3 class="section">13.1 Api</h3>
<p><code>Scm (make-matcher-env)</code>, this will make a matcher db object.
......
......@@ -6,7 +6,7 @@
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="dynamics.html#dynamics" title="dynamics">
<link rel="next" href="database.html#database" title="database">
<link rel="next" href="parsing.html#parsing" title="parsing">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This is a preliminary manual of guile-log package for guile-2.0
......@@ -29,21 +29,21 @@ Copyright (C) 2012 Stefan Israelsson Tampe-->
<a name="dynamic-functions"></a>
<a name="dynamic_002dfunctions"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="database.html#database">database</a>,
Next:&nbsp;<a rel="next" accesskey="n" href="parsing.html#parsing">parsing</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="dynamics.html#dynamics">dynamics</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">1 Overview</h2>
<h2 class="chapter">6 Dynamic functions</h2>
<p>An interesting category of functionality in prolog is their dynamic function framework. They are a generalization of databases and allow to do matching in a scalable manner through indexing. Guile log also support a full indexer for a simplified matcher. And for all matched clauses they will be executed in order acording to how the database is setuped. One can add clauses to the head or to the end, remove clauses according to a pattern and also store states for later rewinding. The state guarding mechanism is either cheap (weak) e.g. it will not remember states as long as the action is above in the stack, else if it backtracks below the stack, state will be stored and restored at reentrence. We also support strong state storage at e.g. postpone support.
<p>To use the api use <code>(use-modules (logic guile-log functional-database))</code>.
<h2 class="chapter">2 Api</h2>
<h3 class="section">6.1 Api</h3>
<p><a name="index-define_002ddynamic-1"></a><a name="index-g_t_003cpush_002ddynamic_003e-2"></a><a name="index-g_t_003clambda_002ddyn_003e-3"></a><a name="index-g_t_003cappend_002ddynamic_003e-4"></a><a name="index-g_t_003cremove_002ddynamic_003e-5"></a><code>SCM (define-dynamic f)</code>, this will make a dynamic function object and bind it to <code>f</code>
<p><a name="index-define_002ddynamic-176"></a><a name="index-g_t_003cpush_002ddynamic_003e-177"></a><a name="index-g_t_003clambda_002ddyn_003e-178"></a><a name="index-g_t_003cappend_002ddynamic_003e-179"></a><a name="index-g_t_003cremove_002ddynamic_003e-180"></a><code>SCM (define-dynamic f)</code>, this will make a dynamic function object and bind it to <code>f</code>
<p><code>G.L. (&lt;push-dynamic&gt; f lambda-dyn)</code>, push a match onto the head of dynamic function <code>f</code>. <code>lambda-dyn</code> is a special lambda typically created through,
......@@ -57,7 +57,7 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<p><code>G.L. (&lt;remove-dynamic&gt; (f a ...))</code>, where <code>f</code> is the dynamic function and <code>a ...</code> the patterns for the arguments that, which matches will be retracted.
<p><a name="index-g_t_003cwith_002ddynamic_002dfunctions_003e-6"></a><a name="index-g_t_003cguard_002ddynamic_002dfunctions_003e-7"></a>The previous set of API is typically what you get to use in prolog. The
<p><a name="index-g_t_003cwith_002ddynamic_002dfunctions_003e-181"></a><a name="index-g_t_003cguard_002ddynamic_002dfunctions_003e-182"></a>The previous set of API is typically what you get to use in prolog. The
downside is that they posses problem w.r.t. leaking data and therefor the next ideom is preferable to use in order to make sure both that one undo any changes to the dynamic variable, but also at reinstation of a state inside the form, it will resore to the same state as when control left the inner of the ideom e.g. The design is to favor fast lookup and adding and removing information is a bit expensive.
<p><code>G.L. (&lt;with-dynamic-functions&gt; (f ...) code ...)</code>, for this form <code>f ...</code>, will be weakly guarded throughout the form e.g. if control leaves the form then the state is stored if needed and at reinstation of state inside <code>code ...</code>, the old state of the dynamic variable will be reinstated. But inside the form state of the dynamic functions is not saved or restored.
......@@ -68,7 +68,7 @@ downside is that they posses problem w.r.t. leaking data and therefor the next i
<p>Finally the last section conserns the ability to compile the dynamic function for as fast lookup as possible, use
<p><a name="index-g_t_003cdynamic_002dcompile_003e-8"></a><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><a name="index-g_t_003cdynamic_002dcompile_003e-183"></a><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.
</body></html>
......@@ -34,13 +34,13 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">15 Overview</h2>
<h2 class="chapter">5 Dynamics</h2>
<p>The main work has been to enable delimeted continuation in guile-log. To do this is not easy because we want to support interleaving, postponing, store/restore, zip like construct as well as acumulation all in one theoretically and computationally sound environment. It's not just to store and restore a stack as in scheme. Guile log is targetted to be effective reinstating states and keep a huge number of states in memory, to do this we note 1. we store a tree of states to compress the overall memory need and keep consing to a lower degree. 2. reinstating state information multiple times is cheap because there is no consing the second time for the main stack (we keep another dynamic stack where we need to reinstate new datastructures at each reinstation. All this means that we must reinstate the same datastructure. Also generally the cc and p fields at the in and out of the generated continuation needs to be patched and in order to support all of guile-log seamlessly one need to make use of guarded variables. In all stackless dynamics like kanren employ is not well suited because this is a nonfunctional modification. The resulting continuation will work almost as one would expect, but one can imagine problematics if the evaluation of the continuation returns a failure thunk intended to jump back into the continuation without normal backtracking. This is not a serious flaw and we do not try to add functionality to support this more than that we would implement new versions of the frameworks, looking at that source code it would be clear how to proceed.
<h2 class="chapter">16 Api</h2>
<h3 class="section">5.1 Api</h3>
<p><a name="index-g_t_003cprompt_003e-181"></a><a name="index-g_t_003cabort_003e-182"></a><a name="index-g_t_003ccatch_003e-183"></a>
<p><a name="index-g_t_003cprompt_003e-173"></a><a name="index-g_t_003cabort_003e-174"></a><a name="index-g_t_003ccatch_003e-175"></a>
<code>G.L. (&lt;prompt&gt; tag data thunk handler)</code>, This will evaluate the guile-log version of a thunk and continue just as with any other thunk. But if an abort with a tag that matches the prompt tag or if the prompt tag is true, any abort will be catched. data will be guile-log dynamic data that will be captured at the abort and transferd back to the prompts context. The handler is of the form
<p><code>(handler tag next kk args ...)</code>, <code>tag</code> is the abort tag, next is a guile-log thunk, that evaluated will try the next handler in the stack. kk is a meta continuation. typically to get the continuaiton <code>k</code>, you do
......@@ -66,7 +66,7 @@ as with prompts, but with the difference that the handler has the form
<p><code>G.L. (&lt;abort&gt; tag lambda args ...)</code>, will look for a handler matching
the tag and then call the handler with <code>(args ...)</code>, see the doc for <code>&lt;prompt&gt;</code>. The lambda should be a guile-log lambda and defines the signature that the continuation inside the handler have.
<h2 class="chapter">17 Example</h2>
<h3 class="section">5.2 Example</h3>
<pre class="verbatim">(use-modules (logic guile-log))
(use-modules (logic guile-log umatch))
......
......@@ -5,6 +5,8 @@
<meta name="description" content="Preliminary Manual">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="parsing.html#parsing" title="parsing">
<link rel="prev" href="parser-combinators.html#parser-combinators" title="parser combinators">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This is a preliminary manual of guile-log package for guile-2.0
......@@ -26,15 +28,16 @@ Copyright (C) 2012 Stefan Israelsson Tampe-->
<div class="node">
<a name="expressions"></a>
<p>
Previous:&nbsp;<a rel="previous" accesskey="p" href="parser-combinators.html#parser-combinators">parser combinators</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="parsing.html#parsing">parsing</a>
<hr>
</div>
<h2 class="chapter">23 Overview</h2>
<h3 class="section">7.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>
<h3 class="section">23.1 Api</h3>
<h4 class="subsection">7.3.1 Api</h4>
<p><a name="index-make_002dopdata-217"></a><code>(make-opdata)</code>, initiates a datastructure to containe needed operator data. The result is a fluid pointing to a functional datastructure.
......
This diff is collapsed.
......@@ -39,18 +39,17 @@ Up:&nbsp;<a rel="up" accesskey="u" href="../index.html#dir">(dir)</a>
<p>Documentation for the Guile-Log Logic Programming Environment for Guile 2.0 v0.4
<ul class="menu">
<li><a accesskey="1" href="umatch.html#umatch">umatch</a>: low level infrastructure.
<li><a accesskey="2" href="guile_002dlog.html#guile_002dlog">guile-log</a>: This is the guile-log basic macro environment
<li><a accesskey="1" href="umatch.html#umatch">umatch</a>: low level infrastructure.
<li><a accesskey="2" href="guile_002dlog.html#guile_002dlog">guile-log</a>: This is the guile-log basic macro environment
<li><a accesskey="3" href="acumulators_002fgenerators.html#acumulators_002fgenerators">acumulators/generators</a>: Hot to collect and generate sequences of solutions.
<li><a accesskey="4" href="postpone.html#postpone">postpone</a>: To postpone a search.
<li><a accesskey="5" href="dynamics.html#dynamics">dynamics</a>: catch prompt abort
<li><a accesskey="6" href="dynamic_002dfunctions.html#dynamic_002dfunctions">dynamic-functions</a>: Dynamicaly add, remove and execute clauses
<li><a accesskey="7" href="database.html#database">database</a>: Prolog like Database, the guile-log kind.
<li><a accesskey="8" href="parsing.html#parsing">parsing</a>: A parsing framework. Enabling to use guile-log's parser
<li><a accesskey="9" href="sed_002fgrep.html#sed_002fgrep">sed/grep</a>: Sed and grep functionalities for scheme
<li><a href="kanren.html#kanren">kanren</a>: Kanren implemented ontop of guile-log
<li><a href="prolog.html#prolog">prolog</a>: iso-prolog
<li><a href="Index.html#Index">Index</a>: Complete index.
<li><a accesskey="4" href="postpone.html#postpone">postpone</a>: To postpone a search.
<li><a accesskey="5" href="dynamics.html#dynamics">dynamics</a>: catch prompt abort
<li><a accesskey="6" href="dynamic_002dfunctions.html#dynamic_002dfunctions">dynamic-functions</a>: Dynamicaly add, remove and execute clauses
<li><a accesskey="7" href="parsing.html#parsing">parsing</a>: A parsing framework.
<li><a accesskey="8" href="sed_002fgrep.html#sed_002fgrep">sed/grep</a>: Sed and grep functionalities for scheme
<li><a accesskey="9" href="kanren.html#kanren">kanren</a>: Kanren implemented ontop of guile-log
<li><a href="prolog.html#prolog">prolog</a>: iso-prolog
<li><a href="Index.html#Index">Index</a>: Complete index.
</ul>
</body></html>
......
......@@ -34,12 +34,12 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">29 kanren</h2>
<h2 class="chapter">9 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.
<h3 class="section">29.1 The fact building blocks</h3>
<h3 class="section">9.1 The fact building blocks</h3>
<p><a name="index-succeed-221"></a><a name="index-fail-222"></a><a name="index-sfail-223"></a><a name="index-all-224"></a><a name="index-all_0021-225"></a><a name="index-all_0021_0021-226"></a><a name="index-all_002dinterleave-227"></a><a name="index-any-228"></a><a name="index-any_002dinterleave-229"></a><a name="index-any_002dunion-230"></a><a name="index-if_002donly-231"></a><a name="index-if_002dsome-232"></a><a name="index-fails-233"></a><a name="index-succeeds-234"></a><a name="index-g_t_003d_003d-235"></a><a name="index-let_002dlv-236"></a><a name="index-project-237"></a><a name="index-project_002fno_002dcheck-238"></a><a name="index-predicate-239"></a><a name="index-g_t_002aequal_003f-240"></a><a name="index-var_003f-241"></a><a name="index-reify-242"></a><a name="index-g_t_005f-243"></a>
<code>succed</code>, This functional item repressents a term that always succeeds.
......@@ -87,7 +87,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's place.
<h3 class="section">29.2 relations</h3>
<h3 class="section">9.2 relations</h3>
<p><a name="index-relation-244"></a><a name="index-fact-245"></a><a name="index-extend_002drelation-246"></a><a name="index-extend_002drelation_002dwith_002drecur_002dlimit-247"></a><a name="index-lift_002dto_002drelations-248"></a><a name="index-intersect_002drelation-249"></a><a name="index-let_002dgls-250"></a>
This is documentation derived from the kanren sources.
......@@ -147,7 +147,7 @@ variables <code>id ...</code>. E.g.
<p><code>(let-gls (id ...) ((name rel) ...) code)</code>, this will create a new realation with arguments <code>id ...</code> and in that create a set af relations names <code>name ...</code> representing <code>rel ...</code> and the names are used in <code>code</code>.
<h3 class="section">29.3 Queries</h3>
<h3 class="section">9.3 Queries</h3>
<p><a name="index-query-251"></a><a name="index-solve-252"></a><a name="index-solution-253"></a>
<code>query (redo-k subst id ...) A SE ...) -&gt; result or '()</code>, The low level macro 'query' runs the goal <code>A</code> in the empty initial substitution, and reifies the resulting answer: the substitution and the redo-continuation bound to fresh variables with the names supplied by the user e.g. <code>redo-k</code> and <code>subst</code>. The substitution and the redo continuation can then be used by Scheme expressions <code>SE ...</code> Before running the goal, the macro creates logical variables <code>id ...</code> for use in <code>A</code> and <code>SE ...</code> If the goal fails, '() is returned and <code>SE ...</code> are not evaluated. Note the similarity with shift/reset-based programming where the immediate return signifies "failure" and the invocation of the continuation a "success" Returning '() on failure makes it easy to create the list of answers.
......@@ -156,14 +156,14 @@ variables <code>id ...</code>. E.g.
<p><code>(solution (v ...) g ...</code>, This is the same as <code>(solve 1 (v ...) g ...)</code>.
<h3 class="section">29.4 Misc</h3>
<h3 class="section">9.4 Misc</h3>
<p><a name="index-trace_002dvars-254"></a><a name="index-partially_002deval_002dsgl-255"></a>
<code>(trace-vars title (var ...))</code>, Will print out a trace expression for <code>var ...</code>.
<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.
<h3 class="section">29.5 Examples</h3>
<h3 class="section">9.5 Examples</h3>
<pre class="verbatim">Example 1, any-union,
(let* ((fact1 (fact () 'x1 'y1))
......
......@@ -5,6 +5,9 @@
<meta name="description" content="Preliminary Manual">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="parsing.html#parsing" title="parsing">
<link rel="prev" href="stream-ideom.html#stream-ideom" title="stream ideom">
<link rel="next" href="expressions.html#expressions" title="expressions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This is a preliminary manual of guile-log package for guile-2.0
......@@ -26,17 +29,17 @@ Copyright (C) 2012 Stefan Israelsson Tampe-->
<div class="node">
<a name="parser-combinators"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="expressions.html#expressions">expressions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="stream-ideom.html#stream-ideom">stream ideom</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="parsing.html#parsing">parsing</a>
<hr>
</div>
<h2 class="chapter">21 Overview</h2>
<h3 class="section">7.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.
<h2 class="chapter">22 Api</h2>
<h3 class="section">22.1 higher order elements</h3>
<h4 class="subsection">7.2.1 higher order elements</h4>
<p><a name="index-f_002dand-185"></a><a name="index-f_002dand_0021-186"></a><a name="index-f_002dand_0021_0021-187"></a><code>(f-and f ...)</code>, higher order function, matches if all <code>f ...</code> matches and returns the values from the last one. Similarly <code>and!</code> only successes ones and for <code>and!!</code> all <code>f ...</code> only sucesses once.
......@@ -52,7 +55,7 @@ Copyright (C) 2012 Stefan Israelsson Tampe-->
<p><a name="index-fn-198"></a><code>(fn f n m)</code>, matches <code>f</code> n to m times
<h3 class="section">22.2 Basic parser functions</h3>
<h4 class="subsection">7.2.2 Basic parser functions</h4>
<p><a name="index-f_002dtag-199"></a><a name="index-f_002dtag_0021-200"></a><a name="index-f_002dtag_002dpr-201"></a><code>(f-tag str)</code>, produces a matcher of the tag <code>str</code>. <code>f-tag!</code> stores that match the standard way and <code>f-tag-pr</code> prints the match on standard output.
......@@ -65,7 +68,7 @@ Copyright (C) 2012 Stefan Israelsson Tampe-->
<p><a name="index-tok_002dws_002a-211"></a><a name="index-tok_002dws_002b-212"></a><code>tok-ws*, tok-ws+</code>, this is an non token generator token e.g. it returns the input state of the out stream. But it does tokenizing by issuing a freeze so it memoizes and will not reparse whitespace. the * version is for 0 or more whitespaces and + for one or more whitespaces. A whitespace is here defined as 'space' 'tab' and 'newline'.
<h3 class="section">22.3 utilities</h3>
<h4 class="subsection">7.2.3 utilities</h4>
<p><a name="index-p_002dfreeze-213"></a><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
......
......@@ -5,7 +5,7 @@
<meta name="description" content="Preliminary Manual">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="database.html#database" title="database">
<link rel="prev" href="dynamic_002dfunctions.html#dynamic_002dfunctions" title="dynamic-functions">
<link rel="next" href="sed_002fgrep.html#sed_002fgrep" title="sed/grep">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
......@@ -29,12 +29,12 @@ Copyright (C) 2012 Stefan Israelsson Tampe-->
<a name="parsing"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="sed_002fgrep.html#sed_002fgrep">sed/grep</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="database.html#database">database</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="dynamic_002dfunctions.html#dynamic_002dfunctions">dynamic-functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">18 Overview</h2>
<h2 class="chapter">7 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.
......
......@@ -34,13 +34,13 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">12 Postpone, a framework for postponing guile-log evaluations.</h2>
<h2 class="chapter">4 Postpone, a framework for postponing guile-log evaluations.</h2>
<p>This code is available from <code>(logic guile-log postpone)</code> You may have noticed that guile log is a framework to do tree searches to meet a certain criteria and during the path in the tree create data structures that are able to undo and also redo it's state. Most people when approaching this will sooner or later be bitten by the NP hardness of many interesting problems. The solution might then be to try intelligent guesses in which branch the gold is hiding. What one would like to do is try a set of branches, freeze the different states and at that point create some sort of index that represent the likelihood of the gold lying buried beneath. Then an overall global decision can be taken and only the most promising paths will be further examined. It is for this use case the following system is constructed. Postpone mix well with the rest of prolog, but especially the <code>&lt;zip&gt;</code>, forms might behave unexpectedly due to teh postpone mechansim interfering with the synch and produce bad result.
<h2 class="chapter">13 Api.</h2>
<h3 class="section">4.1 Api.</h3>
<p><a name="index-postpone-179"></a><a name="index-postpone_002dframe-180"></a>
<p><a name="index-postpone-171"></a><a name="index-postpone_002dframe-172"></a>
<pre class="verbatim">G.L. (postpone val power)
G.L. (postpone-frame limit fact maxsize)
</pre>
......
......@@ -34,9 +34,20 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">30 Overview</h2>
<h2 class="chapter">10 Prolog</h2>
<p>Bla
<p>Guile log sports also a 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 shure it is alpha software. With this most programs written in iso prolog should work. The intention is to enhance this interface so that the bulk of already written prolog programs should be able to be run on guile. We will also add the fetures unique to guile-log and hence ehance the prolog experience.
<ul class="menu">
<li><a accesskey="1" href="running.html#running">running</a>: How to hook in prolog code
<li><a accesskey="2" href="deviations.html#deviations">deviations</a>: What is different and not according to standard and why.
<li><a accesskey="3" href="modules.html#modules">modules</a>: How to handle name spacing
<li><a accesskey="4" href="prolog_002ddynamic_002dfunctions.html#prolog_002ddynamic_002dfunctions">prolog-dynamic-functions</a>: A discussion of guile log's version of this
<li><a accesskey="5" href="accessing_002dscheme.html#accessing_002dscheme">accessing-scheme</a>: How to execute scheme inside
<li><a accesskey="6" href="dynamic_002dfeatures.html#dynamic_002dfeatures">dynamic-features</a>: Special construct to manage dynamic objects
<li><a accesskey="7" href="prolog_002dlibraries.html#prolog_002dlibraries">prolog-libraries</a>: Libraries that exposes guile-log features
<li><a accesskey="8" href="internals.html#internals">internals</a>: A short discussion of the prolog internals used.
</ul>
</body></html>
......@@ -35,11 +35,11 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">24 Overview</h2>
<h2 class="chapter">8 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>.
<h2 class="chapter">25 Api</h2>
<h3 class="section">8.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.
......@@ -49,7 +49,7 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<p><code>(par-sed match code #:key (str q-false) (com q-false))</code>, This is a sed utility that knows about scheme.
<h2 class="chapter">26 The scheme matcher.</h2>
<h3 class="section">8.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.
......@@ -68,11 +68,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.
<h2 class="chapter">27 Building the result.</h2>
<h3 class="section">8.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.
<h2 class="chapter">28 Example</h2>
<h3 class="section">8.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.
......
......@@ -5,6 +5,8 @@
<meta name="description" content="Preliminary Manual">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="parsing.html#parsing" title="parsing">
<link rel="next" href="parser-combinators.html#parser-combinators" title="parser combinators">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This is a preliminary manual of guile-log package for guile-2.0
......@@ -26,11 +28,12 @@ Copyright (C) 2012 Stefan Israelsson Tampe-->
<div class="node">
<a name="stream-ideom"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="parser-combinators.html#parser-combinators">parser combinators</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="parsing.html#parsing">parsing</a>
<hr>
</div>
<h2 class="chapter">19 Api</h2>
<h3 class="section">7.1 Stream ideom api</h3>
<p><a name="index-define_002dguile_002dlog_002dparser-184"></a>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
......@@ -42,7 +45,7 @@ Copyright (C) 2012 Stefan Israelsson Tampe-->
<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.
<h2 class="chapter">20 Example</h2>
<h4 class="subsection">7.1.1 Example</h4>
<p>The parsing framwork is using
......
This diff is collapsed.
......@@ -16,9 +16,11 @@
compile-prolog-string compile-prolog-file
save-operator-table prolog-run
load-prolog clear-directives
init-char-conversion
save-char-conversion-table
reset-char-conversion
reset-operator-map
reset-flags
reset-prolog
;; Math
sin cos atan exp log sqrt
......@@ -97,6 +99,12 @@
)
#:export (make-unbound-term))
(define reset-flags init-flags)
(define (reset-prolog)
(reset-flags)
(reset-char-conversion)
(reset-operator-map))
(define-syntax-rule (make-unbound-term a)
(begin
(define a (make-unbound-fkn 'a))
......
......@@ -14,14 +14,14 @@
#:export
(init-char-conversion char-convert char-conversions->assq
(reset-char-conversion char-convert char-conversions->assq
save-char-conversion-table
assq->char-conversions
current_char_conversion init-char-conversion))
(define *conversion* (make-fluid vlist-null))
(define (init-char-conversion)
(define (reset-char-conversion)
(fluid-set! *conversion* vlist-null))
(define (char-convert ch)
......
......@@ -14,10 +14,10 @@
(_ . GL:_)))
#:re-export (*prolog-file* get-refstr)
#:export (prolog-parse define-parser-directive add-op rem-op
reset-operator-map
define-parser-directive-onfkn prolog-parse-read
ops->assq assq->ops
get-ops
round floor ceil))
get-ops))
(define do-print #f)
......@@ -120,6 +120,9 @@
(xfy 200 ^)
,@(map (lambda (x) `(fy 200 ,x)) '(- "\\"))))
(define *standard-opmap* (fluid-ref *prolog-ops*))
(define (reset-operator-map)
(fluid-set! *prolog-ops* *standard-opmap*))
(define fop ((mk-fop *prolog-ops*) '(fy fx xfx xfy yfx yf xf)))
(define fbinop ((mk-fop *prolog-ops*) '(xfx xfy yfx)))
......
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