c files compiles, some more documentation

parent b76f2c73
......@@ -1689,26 +1689,32 @@ the orders of fact1 and fact2 etc in the definitions of R1 and R2.
@node prolog
@chapter Prolog
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.
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 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 well thought out library to tell how you want the dynamism to work at a very fine grained level.
@menu
* running:: How to hook in prolog code
* deviations:: What is different and not according to standard and why.
* modules:: How to handle name spacing
* scheme:: Hooking in scheme expressions
* closures:: Using closures in prolog
* prolog-dynamic-functions:: A discussion of guile log's version of this
* accessing-scheme:: How to execute scheme inside
* dynamic-features:: Special construct to manage dynamic objects
* prolog-libraries:: Libraries that exposes guile-log features
* internals:: A short discussion of the prolog internals used.
@end menu
@node running
@section Introduction
@section Seting up and running prolog programs
At this point we do not support an interactive shell for prolog. A task on the todo list, but you can run macros that takes a string and outputs a compiled guile log snippet and by this e.g. define logic functions using prolog. It is also possible to refere to a file and by that load a prolog file's contents into a scheme file. There is also tools to reset the prolog parser in case it changes it's state by e.g. defining operators or character translations. The typical usecase is to provide a small module wrapper, reset the parser and then add the prolog file.
@subsection Api
@findex compile-prolog-string
@findex compile-prolog-file
The iso-prolog library is resolved by,
@code{(use-modules (logic guile-log iso-prolog))}
First the compiler macros,
@code{(compile-prolog-string string)}, this will compile a prolog program in @code{string} and output a guile-log program at macro expansion time.
......@@ -1731,6 +1737,22 @@ Then to reset the parser and prolog flags use,
@code{(rest-prolog)}, will do all of the above rest functions.
To run a prolog program one need to use a special program that essentially will
setup an suitable error handler for prolog and issue a guile-log @code{<run>} command e.g.,
@code{(prolog-run n (v ...) code ...)}, here @code{n} is the maximum number of
solutions to search for, or @code{*} to search for all solutions. @code{v ...} is a set of logical variables used and for which solution are collected, @code{code ...} is a guile-log command, but to make it simple just call a startup prolog function with it.
@subsection Example
@verbatim
(use-modules (logic guile-log iso-prolog))
(reset-prolog)
(compile-string "f(X,Y) :- (X=1,Y=2;Y=3);X=Y.")
(prolog-run * (X Y) (f X Y))
->
@end verbatim
@node deviations
@section Known deviations from iso prolog specification.
The known deviations are
......@@ -1745,28 +1767,75 @@ The logic is currently,
@code{f(...,'nm',....)}, here @code{nm} is translated to a scheme string. and likewise for list arguments. There is a distinction here because characters in prolog is also atoms and then the namespacing mechanism currently used, makes prolog code a headache to use if we translated everything to atoms directly (an 'a' in one module would not be an 'a' in another module). In stead it is possible to call with a string in which case the current module is used for lookup. And unification of a string 'a' and a atom a is always true whatever the module is involved. (two atoms does not translate well). This is again a tweak to support modules sanely and it is expected to always work. To note, it is possible to namespace a @code{'nm'} item by forcing a namespace on it. The story is a bit complex, the main thing to remember is to explicitly sigil a @code{'nm'} with the namespace operator if one want and atom and in case one suspect a string is gotten as an argument, it is possible to make an operator through a unification with a namespaced variable.
@subseciton closed files
Closed files cannot be gotten through a general seek of active streams.
@subsection closed files
Closed files cannot be gotten through a general seek of streams.
@subsection seek
seek in binary files is not supported (yet).
@subsection modules
there is some effort to styandardize modules, we do not explicitly add module functionality to prolog, users are advised to write scheme wrappers or inlined scheme code in the prolog file/string.
there is some effort to standardize modules, we do not explicitly add module functionality to prolog, users are advised to write scheme wrappers or inlined scheme code in the prolog file/string.
@node modules
@section Module system and prolog
a
We support @code{@@} and @code{@@@@} operators to resolve atoms module meaning. The syntax is @code{name@@module} which names files in a special module directory in the guile namespace @code{(language prolog modules)}. @code{@@} is refering to symbols in the public interface and @code{@@@@} refers to symbols in the whole private module namespace. We also support a guile-log reference through e.g. @code{name@@(logic,guile-log,iso-prolog)}. atoms can either be namespaced in or are strings, that will be namespaces as soon it touches a construct with a namespace in, e.g. @code{X@@module = Y} will make sure that if @code{X} gets bounded, it will if @code{Y} is a string, try to produced a namespaced item. Managing modules will either be done by the scheme wrapper or by inlined scheme expression.
@subsection Example
@verbatim
:- scm[(use-modules (logic guile-log guile-prolog zip)]
:- scm[(export a b c)]
:- scm[(re-export e f g)]
@end verbatim
@node scheme
@section hooking in scheme expressions,
We can insert scheme expressions with the construct @code{scm[sexp]}. You can insert it like
1) directives
@code{:- scm[(export a b c)]}
2) function arguments and list arguments
@code{f(X) :- g(X, scm[(dub (<scm> X))], scm[*global-variable*])}
3) In expression constructs
@code{f(X) :- X is scm[(dub X)]}.
@node closures
@section closures in prolog
Closures is an interesting construct and we support three variants of them.
1) Full blown @code{letrec} environment,
@verbatim
f(X,Y,L) :- h(X,Y,Z),
k(lambda{ flam(X,Y) :- X = [v[Y],Y].
lambda(U) :- flam(v[Z],U).}).
@end verbatim
E.g. the ideom are
@code{name@{just usual prolog definitions here@}} with @code{name} naming
the function which will be the lambda handle.
2) simple one line lambdas
@code{name@{X,Y | code ...@}}
and 3)
@code{name@{@{code ...@}@}}, e.g. a closure with no arguments.
The @code{name} will be used in printed representations, refering not to the closure object but the closure code. Therefore it must be unique to the module or it will clobber or be clobbed.
To be able to refere to a variable in the outer context onen need to enclose it with @code{v[Var]}. Then it will match a variable named @code{Var} that has normally been lexically bound in a prolog program. You may refer to global scheme variables as well by @code{scm[...]}.
Closures will be transparent e.g. two closures unifies when all the closure
variables unifies and the code is equvalent. Also the system works with
@code{copy_term}, can be put into @code{asserta} and @code{read-term}'ed and
@code{write-term}'ed. All should work smoothly.
@node prolog-dynamic-functions
@section Explaing the guile-log dynamic functions
a
@node accessing-scheme
@section Accessing scheme and guile-log from prolog
a
@node dynamic-features
@section Dynamic features
a
......
......@@ -36,17 +36,18 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<h2 class="chapter">10 Prolog</h2>
<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.
<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 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 well thought out library to tell how you want the dynamism to work at a very fine grained level.
<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.
<li><a accesskey="4" href="scheme.html#scheme">scheme</a>: Hooking in scheme expressions
<li><a accesskey="5" href="closures.html#closures">closures</a>: Using closures in prolog
<li><a accesskey="6" href="prolog_002ddynamic_002dfunctions.html#prolog_002ddynamic_002dfunctions">prolog-dynamic-functions</a>: A discussion of guile log's version of this
<li><a accesskey="7" href="dynamic_002dfeatures.html#dynamic_002dfeatures">dynamic-features</a>: Special construct to manage dynamic objects
<li><a accesskey="8" href="prolog_002dlibraries.html#prolog_002dlibraries">prolog-libraries</a>: Libraries that exposes guile-log features
<li><a accesskey="9" href="internals.html#internals">internals</a>: A short discussion of the prolog internals used.
</ul>
</body></html>
......
......@@ -32,17 +32,15 @@
(format #f "~a" (procedure-name a))
(format #f "~a" a)))))
(define-syntax-rule (prolog-run n a ...)
(prolog-run_ n (<lambda> () a ...)))
(define (prolog-run_ n lam)
(define-syntax-rule (prolog-run n v code ...)
(scheme-wrapper
(lambda ()
(begin
(<clear>)
(<run> n ()
(<run> n v
(<catch> 'prolog #f
lam
(<lambda> () code ...)
(<lambda> (tag next l)
(<format> #t "DYNAMIC ERROR:~%=> ~a~%~%" (var->code (<scm> l)))
(<ret> (<scm> l)))))))))
......@@ -107,7 +107,7 @@ SCM rguard_skip(SCM rguard, SCM var);
SCM get_l_k_part(SCM k, SCM guards)
{
SCM pt;
for(pt = guard; SCM_CONSP(pt); pt = SCM_CDR(pt))
for(pt = guards; SCM_CONSP(pt); pt = SCM_CDR(pt))
{
SCM *v = SCM_I_VECTOR_WELTS(SCM_CAR(pt));
if(v[D_LGUARD_VAR] == k)
......@@ -164,7 +164,7 @@ SCM has_old_ref(SCM k, SCM guards)
{
int found = 0;
SCM pt;
for(pt = guard; SCM_CONSP(pt); pt = SCM_CDR(pt))
for(pt = guards; SCM_CONSP(pt); pt = SCM_CDR(pt))
if(SCM_CAAR(pt) == k)
return 1;
return 0;
......@@ -173,7 +173,7 @@ SCM has_old_ref(SCM k, SCM guards)
SCM get_oldkind(SCM k, SCM guards)
{
SCM pt;
for(pt = guard; SCM_CONSP(pt); pt = SCM_CDR(pt))
for(pt = guards; SCM_CONSP(pt); pt = SCM_CDR(pt))
{
if(SCM_CAAR(pt) == k)
return SCM_CDAR(pt);
......@@ -207,7 +207,7 @@ SCM_DEFINE(undo_safe_variable_lguard, "gp-undo-safe-variable-lguard", 3, 0, 0,
vnew[D_OLD_K] = old_kind;
}
else
return SCM_UNSPECIFY;
return SCM_UNSPECIFIED;
}
gp->dynstack = scm_cons(vnew_, gp->dynstack);
......@@ -507,7 +507,7 @@ SCM manage_dyn_wind(SCM obj, SCM K, SCM *rguard) {
*rguard = scm_cons(scm_cons(v[D_LGUARD_VAR], v[D_LGUARD_K]), *rguard);
else
*rguard = scm_cons(scm_cons(v[D_LGUARD_VAR], v[D_LGUARD_K]),
rguard_skip(*rguard, var));
rguard_skip(*rguard, v[D_LGUARD_VAR]));
return obj;
}
......@@ -601,7 +601,7 @@ SCM unwind_dynstack_it(SCM pp, SCM *rguard)
if(id == D_LGUARD)
{
SCM var = v[D_LGUARD_VAR];
if(v[D_OLD_K] == SCM_BOL_F)
if(v[D_OLD_K] == SCM_BOOL_F)
*rguard = rguard_skip(*rguard, var);
else
*rguard = scm_cons(scm_cons(var,v[D_OLD_K]),rguard_skip(*rguard, var));
......@@ -619,7 +619,7 @@ SCM unwind_dynstack_it(SCM pp, SCM *rguard)
*rguard);
else
*rguard = scm_cons(scm_cons(v[D_RGUARD_VAR], v[D_RGUARD_K]),
rguard_skip(*rguard, var));
rguard_skip(*rguard, v[D_RGUARD_VAR]));
return pp;
}
......
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