Next: LLAMA - The Up: Integrating Relations and Previous: Examples

Implementing Extra-logicals via LL

A very flexible way of introducing extensions in relational languages is by specifying them in LL. In the following, a simple REL extension is described: global variables.

Global variables can be implemented by allowing the following two LL functions, setvar and getvar, to be accessed from REL:

(defun setvar (var value)
  (eval (list 'setq var (list 'quote value))))

(defun getvar (var)
  (eval var))

(setvar var value) sets the global LL variable var to value by evaluating (setq var 'value). (getvar var) returns the value of the global LL variable var by simply evaluating var.

From the point of view of REL, such a variable is a `constant' changeably associated with a term.

Global variables are useful in REL in two situations:

  1. when computed values have to live longer than a query (this is usually the case for programs with user interaction and/or operating system access)
  2. when computed values have to survive backtracking

The second situation occurs when all solutions of a query have to be collected: bagof in PROLOG or tupof in RELFUN.

In pure PROLOG and RELFUN, it is impossible to collect all solutions of a query: intermediate results are reset when backtracking occurs, which is used to generate the next solution; thus all computed values are lost. In order to overcome this difficulty, bagof in PROLOG and tupof in RELFUN were introduced.

These extra-logicals can easily be implemented via global variables: a global variable holds a stack of lists containing the intermediate results (a stack is necessary because it is possible that in the execution of a tupof another tupof call occurs).

Next: LLAMA - The Up: Integrating Relations and Previous: Examples

Harold Boley & Michael Sintek (