Alexander Burger wrote:
Hi Cle,

Hello Alex,


No problem! Let's generate documentation :-)

yeah! That is a nice idea. Especially as your Pilog is a more complete Prolog as those implementation I've seen used by other Lisp systems. I formerly had the intention to use Java and tuProlog for my task at hand, but then I discovered picoLisp. Now I find, that Pilog is nearly (if not fully) as powerful as Prolog, I really enjoy to learn it to try, if my problem can be solved with it in a nicer manner ... :-)

So yes, let us generate some 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' ...

Ah, ok! 'findall/3' has following signature in Prolog:

   findall(Var, Pred(Var), List).

Will find all solutions/bindings of Var for that Pred(Var) is successful. Those bindings will be collected into the list List. For instance:

   findall(X, member(X, [5, 4, 3]), L),

Should find all X, where member(X, [5,4,3]) could be proven successful and bind those X into list L. So after all, L will contain the list [5, 4, 3].

So it is usable in other Prolog clauses to get all solutions of a clause without backtracking ...


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.

Ok, here was an error of mine: I thought, I also have to use '->' to get the value of @X and @Y. But in this Lisp expression it seems not to be necessary to use '->' as in Lisp expressions of Pilog clauses. Understood!

But another thing is, when I do this

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

It will return all @X that took part on all solutions. Now I ask myself, what kind of 
"Prg" is a @X?

'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.

Ok, I understand this ... nice! :-)


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! ;-)

Ahhh ... I had seen this definition, but its consequences were not totally clear to me! Really clever! I should try to put this into my trick pocket :-)


Thanks again for you exhaustive explanations. I wish you a nice day ... my day is over for today ;-)



Reply via email to