28 Nov 2014 tampe   » (Journeyer)


If I'm going to do this an infinite number of times, I can just as well say I did success in doing so and get a good night sleep

I just released a new version of guile-log e.g. logic programming in guile scheme. This release has a few major improvement. The most noteworthy of them are

Support for tablating, e.g. prolog versions of memoisations. There are a few important facts to note First of all the memoisation means that many infinite recursions will success and you can get meaning full answer out of


f(X) :- f(X).

The meaning with memoisation is of cause if f is continued ad infinite and never binds X then f will succeed and X is not bound. This is a nice feature together with good support of recursive datastructures that is now included in guile-log. The other pecularity is that for a given input the code can yield many outputs via backtracking. So it is not a easy peasy thing to churn out. I am not by any means first in producing such a tablating system. The most interesting thing though is that the machinery to implement this was (almost) already there. And the solution is simply just a meta programming on those tools.

The system works by for each templated function have a functional hash from any input to a list of outputs that may not be a unique list. As new solutions are produced, the new solutions is consed on the list, in evaluating the function it will lookup the list of solutions and the produce them as answers backtrackingly. when all solutions have been produced, it will then lookup the functional datastructure again and see if there is any new solutions, if not it will store a continuation and then fail. There will be a base e.g. the first time the function is called that if all continuation points have failed restart all continuations, each of them will reevaluate if there is any new solutions to produce and if they all fail the next round a fixpoint is found an no new solutions is produced. Neat. Be careful with negation (do you know why). Let's show some prolog ...


memo.scm:
------------------------------------
(compile-prolog-string
"
-functorize(tabling).
ff(X) :- (X=[Y,A,B]),ff(A),ff(B),(Y=1;Y=2).
"
------------------------------------
scheme@(guile-user)> (use-modules (logic guile-log iso-prolog))
scheme@(guile-user)> (load "memo.scm")
scheme@(guile-user)> ,L prolog
Happy hacking with Prolog! To switch back, type `,L scheme'.
prolog@(guile-user)> .rec ff(X).

X = {0}[1, ref[0], ref[0]]
more (y/n/a/s) > s
prolog@(guile-user)> .10 .c

X = {0}[2, ref[0], ref[0]]

X = {0}[1, ref[0], {1}[1, ref[1], ref[1]]]

X = {0}[2, ref[0], {1}[1, ref[1], ref[1]]]

X = {0}[1, ref[0], {1}[2, ref[1], ref[1]]]

X = {0}[2, ref[0], {1}[2, ref[1], ref[1]]]

X = [1, {0}[1, ref[0], ref[0]], {1}[1, ref[1], ref[1]]]

X = [2, {0}[1, ref[0], ref[0]], {1}[1, ref[1], ref[1]]]

X = [1, {0}[1, ref[0], ref[0]], {1}[2, ref[1], ref[1]]]

X = [2, {0}[1, ref[0], ref[0]], {1}[2, ref[1], ref[1]]]

X = [1, {0}[1, ref[0], ref[0]], {1}[1, ref[1], {2}[1, ref[2], ref[2]]]]
$1 = stalled
prolog@(guile-user)>

Not the same solution can show up many times in this infinite list. It is possible to use tools that make sure the list is unique but that is expensive and is not shown here. Also note how one can issue an 's' and return to the guile prompt from where state management can be done as well as taking 10 values as shown above.

As shown above recursive aware unification as well as many other recursive aware operations can now be enabled via a prolog goal or the .rec switch at command line

A modified bdw-gc has been made (see the guile-log doc's) and code inside guile's C layer have enabled fully garbage collected prolog variables. Now most normal prolog code will be safe to use even in a server setup where you basically tail call forever and temporary bound variables will not blow the stack. This was a pretty difficult thing to get fully working. A really nice hack indeed.

swi prologs attributed variables and coroutines have been implemented at least partly and with some extra bells and whistles. This feature mean that you can hook in code that will be executed when functions are bounded to specific values or well just bounded, lookup these features in the swi-prolog manual if you are interested, pretty cool.

operator bindings are now name spaced, meaning that by importing a module operators can get a new meaning, this can be used to take advantage of guiles number tower and not adhere strictly to iso-prolog.

Ok there is a few more points in the release, download it and have a play. I'm basically the only user and implementor so it is only a cool alpha software. I'm now heading towards being able to compile at least parts of the swi prolog system, to get more testing and because it is a nice bite to chew on, getting good prolog compability regarding the module system and a few more points is the goal.


Happy hacking and have fun!

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!