Hi Cle,

> I try to read pilog.l before I ask questions, but I have to admit, it is 
> still a bit difficult to understand for me right now. Perhaps it will 
> get easier eventually if I reach a certain level of understanding :-)

No problem! Let's generate documentation :-)

> Another question arose yet. I try to find an equivalent of Prolog's 
> findall/3 predicate. I guess, I can use the Lisp function 'solve' for 
> this purpose, yes?

Actually, I don't know 'findall' ...

'slove' (and its sister function 'pilog') is the interface for calling
Pilog from Lisp. We have discussed already the opposite direction
(calling Lisp from Pilog).

'solve' and 'pilog' are just glue functions to the internal workhorses
'goal' and 'prove', as is also the interactive query function 'query'
(which in turn is used by '?').

>     (de solve ("CL" . "Prg") ...)
> For what is the "Prg" standing here? I assumed I can put a Lisp command 
> ...
> "Prg" irritates me a bit; doesn't it stand for Program?

Correct. "Prg" is a list of executable s-expressions.

"CL" is a list of Pilog clauses.

In general, a list of clauses may be preceded of an alternating sequence
of Pilog variables and Lisp-expressions. The Pilog variables will be
bound to the results of these expressions, to allow the import of values
from the Lisp world into the Pilog world.

This feature is also available in '?' / 'query':

   : (? @L (list 'a 'b 'c) (append @X @Y @L))
    @L=(a b c) @X=NIL @Y=(a b c)
    @L=(a b c) @X=(a) @Y=(b c)
    @L=(a b c) @X=(a b) @Y=(c)
    @L=(a b c) @X=(a b c) @Y=NIL
   -> NIL

Now, 'solve' does not prove these clauses interactively, but returns an
association list of the results (i.e. all Pilog bindings):

   : (solve '(@L (list 'a 'b 'c) (append @X @Y @L)))
   -> (((@L a b c) (@X) (@Y a b c)) ((@L a b c) (@X a) (@Y b c)) ((@L a b c) 
(@X a b) (@Y c)) ((@L a b c) (@X a b c) (@Y)))

   : (more @)
   ((@L a b c) (@X) (@Y a b c))
   ((@L a b c) (@X a) (@Y b c))
   ((@L a b c) (@X a b) (@Y c))
   ((@L a b c) (@X a b c) (@Y))
   -> NIL

Note that in the call to 'solve', the "Prg" argument was empty. If you
supply a "Prg", the Pilog variables '@X', '@Y' etc. are bound to the
values in the CDR parts of the assoc list, and then "Prg" is executed.
This allows further processing of the values:

   : (solve '(@L (list 'a 'b 'c) (append @X @Y @L))
      (pack @X "-" @Y) )
   -> ("-abc" "a-bc" "ab-c" "abc-")

Here, "Prg" consists of a single call to 'pack', which produces the
above output.

'pilog' is similar to this second call of 'solve', but avoids the
generation of a list, and calls "Prg" directly for each set of results.
In applications, 'pilog' is therefore used more often, a typical case is
the generation of database reports.

   : (pilog '(@L (list 'a 'b 'c) (append @X @Y @L))
      (prinl @X "-" @Y) )
   -> NIL

> Further: 'solve' seem to return a list of all solutions, whereas 'pilog' 
> seem to return only the last result of all solutions. Is this correct?

Yes, as you see you are close to the truth. Just that 'pilog' is
typically used for side effects, and not so much for the return value.

> Ah, still another think I wonder ... during reading of pilog.l I found 
> several occurrences of '(repeat)' within that file. What purpose do they 
> serve? They seem to play together with 'be' but I cannot really grasp 
> its purpose probably, I think. It seems only to be a shortcut for a self 
> repeating clause, doesn't it? So is
>     (be repeat)
>     (repeat)
> is equivalent with
>    (be repeat)
>    (be repeat () (repeat))
> ? Is this is the only purpose of the Lisp 'repeat'?

Yes. But with a little but important difference: The second case is
recursive, and due to the lack of tail recursion this is problematic for
large result sets.

However, the above implementation of 'repeat' does indeed introduce some
limited kind of tail recursion, because it destructively modifies the
current rule set in such a way that the rules form a circular list. The
function 'repeat' (the one that is called after (be repeat) or other
rule definitions) does

   (de repeat ()
      (conc (get *Rule T) (get *Rule T)) )

So this rule set will produce an unlimited supply of results! ;-)

- Alex
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to