Next: , Up: prolog   [Index]


16.1 Seting up and running prolog programs

At this point compiling prolog is not supported via the general compiling framework. 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.

16.1.1 Api

The iso-prolog library is resolved by,

(use-modules (logic guile-log iso-prolog))

First the compiler macros,

(compile-prolog-string string), this will compile a prolog program in string and output a guile-log program at macro expansion time.

(compile-prolog-file filename), this will replace the form with a macroexpanded scheme verision of the a prolog program referenced by filename.

Then to reset the parser and prolog flags use,

(reset-operator-map)

(reset-char-conversion)

(reset-flags)

(reset-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 <run> command e.g.,

(prolog-run n (v ...) code ...), here n is the maximum number of solutions to search for, or * to search for all solutions. v ... is a set of logical variables used and for which solution are collected, code ... is a guile-log command, but to make it simple just call a startup prolog function with it.

16.1.2 Example

  (use-modules (logic guile-log iso-prolog))
  (reset-prolog)
  (compile-prolog-string "f(X,Y) :- (X=1,Y=2;Y=3);X=Y.")
  (prolog-run * (X Y) (f X Y))
$1 = ((1 2) (v0 3) (v0 v0))

Next: , Up: prolog   [Index]