[comp.lang.prolog] PROLOG Digest V5 #47

PROLOG-REQUEST@SUSHI.STANFORD.EDU (Chuck Restivo, The Moderator) (07/20/87)

PROLOG Digest            Monday, 20 Jul 1987       Volume 5 : Issue 47

Today's Topics:
                     Query & Symbolics & CProlog,
            Implementation - Assert & Retract & Semantics,
                         LP Library - WARPLAN
----------------------------------------------------------------------

Date: Wed 15 Jul 87 08:47:25-CDT
From: David Gadbois <CGS.GADBOIS@R20.UTEXAS.EDU>
Subject: Symbolics Prolog

I am trying to get a large, existing Prolog program to work on a
Symbolics 3620, and to improve the program somewhat. It's not a very
pleasant task, since the Symbolics Prolog programming environment is
almost non-existent, and the only degugging predicates implemented are
the spy and listing ones.

Has anyone out there worked with Symbolics Prolog? Has anyone worked
on improving it? I'm told Symbolics is coming out with a debugging
package this winter, but that's an awfully long time to wait.

-- David Gadbois

------------------------------

Date: Fri, 17 Jul 87 12:55 CST
From: <KUSALIK%SASK.BITNET@forsythe.stanford.edu>
Subject: bug (?) in CProlog parser

This problem presents itself in CProlog 1.5.
It is best demonstrated by the following example.

Consider the program
        test( [] ).
        test( [X|L] ) :- atomic( X ), test( L ).

(i.e. just want to test if everything in a list is atomic).
Now consider the following dialogue with CProlog
        | ?- test( [..] ).

        yes
        | ?- test( [..,a] ).

        yes
        | ?- test( [..,a,b] ).

        yes
        | ?- test( [a,..] ).

        ***Syntax error***
        test( [a,..
        **here**
        ] ).
        | ?- test( [ a, .. ] ).

        ***Syntax error***
        test( [ a, ..
        **here**
        ] ).
        | ?- test( [ a , '..' ] ).

        ***Syntax error***
        test( [ a , '..'
        **here**
        ] ).
        | ?- test( [a|[..]] ).

        yes

So the question is, why doesn't the parser like constant '..' as the
last element of a list (in "list notation") with more than one
element?

------------------------------

Date: 16-Jul-1987 1506
From: weinberg%aitg.DEC@decwrl.dec.com
Subject: Counting Things

I wish to differ with Tim Finin's reply to Doug Collinge's query.
SETOF/BAGOF is not a good (or even a correct) way to count clauses for
a given predicate (unless the goal in the 'bagof' or 'setof' call is
clause/2).  Referring back to Doug Collinge's original example:

        ?- bagof(X, r(X),  B).

collects a list of all the possible ways of proving the goal r(X).
This is not necessarily the same as the list of all clauses for r/1.
For example if the definition of r/1 were:

        r(X) :- s(X).

        s(alligator).
        s(crococile).

then B would be bound to a list of length two even though there is
only one clause for r/1. Using 'setof' instead of 'bagof' is even less
likely to get correct results since 'setof' automatically removes
duplicate entries from the list.

The query bagof(X, clause(r(X), _), B) should correctly bind B to a
list whose length is the same as the number of clauses for r/1. This
is probably the best way to count clauses in the database. It is
similar to the program Tim Finin proposes except that his only counts
unit clauses. 

Changing 'clause(X, true)' to 'clause(X, _)' in Tim Finin's program
should cure this problem. In any case if bagof/3 has been at all
cleverly implemented in the Prolog you are using, the bagof( X,
clause( r( x ), _ ), B ) query should be more efficient than the
equivalent program using asserts and retracts.

-- Toby Weinberg

------------------------------

Date: Fri, 17 Jul 87 12:55:54 +1000
From: munnari!mulga.oz!lee@uunet.UU.NET
Subject: counting and natural numbers

        % X is a natural number (efficient generator)
nat(X) :- le(0, X).

        % X =< Y
le(X, X).
le(X, Y) :-
        Z is X+1,
        le(Z, X).

As Tim Finin pointed out, you can use bagof (or setof if you dont want
to count duplicates) or findall (should be faster if your
implementation is the same standard as bagof) or with a failure driven
loop (on some systems you will need 'once' around the retract or a cut
after it and an extra predicate).  NU-Prolog also has a count
predicate.  All these methods work (or can be made to) for counting
solutions to any goal.  For the particular case of counting the number
of clauses in a predicate, there probably should be a more direct
method.  I know there is a hack possible in MU-Prolog.  I dont know
about other systems.

-- Lee Naish

------------------------------

Date: Fri, 17 Jul 87 14:47:28 PDT
From: Tim Lindholm <quintus!elvis!tim@Sun.COM> 
Subject: Semantics of assert/retract

Anyone interested in the reasoning behind the change of semantics for
dynamic code between releases 1.6 and 2.0 of Quintus Prolog should
read "Efficient Implementation of a Defensible Semantics for Dynamic
Prolog Code", by myself and Richard O'Keefe.  This is available in the
proceedings of the 1987 International Conference on Logic Programming,
from MIT Press. [will actually be available at the beginning of
October -ed]

The paper argues that there are just two reasonable semantics for
dynamic code.  The semantics initially implemented by Quintus in
releases 1.0 through 1.6 is shown to result in a serious inefficiency
in all WAM-based Prologs, independent of whether the dynamic code is
interpreted, compiled and emulated, or native code compiled.  (It is
impossible to get last call determinacy detection when running dynamic
code, including the determinacy detection otherwise made available by
indexing.)  The paper also shows how the other Good semantics, which
we think is arguably Better than the first and have implemented in
Quintus Prolog Release 2.0, can be implemented in a WAM-based system
with efficiency comparable to that of the Prolog system's static code.

-- Tim Lindholm

------------------------------

Date: Fri, 17 Jul 87 09:32:48 CDT
From: Manuel Hermenegildo <herme%pp.mcc.com@mcc.com> 
Subject: Assert & Retract

The reasons in the minds of the Quintus people for the new semantics
for assert and retract were explained by Tim Lindholm and Richard
O'Keefe in their paper,

"Efficient Implementation of a Defensible Semantics for Dynamic Prolog
Code"

presented at the 4th. Int'l Con. on Logic Programming in Melbourne,
Australia, last May.  The proceedings are published as two volumes,
edited by Jean Louis Lassez, in the MIT press series in Logic Programming.
The paper is of use both in understanding the behaviour of Quintus 2.0
and the rationale behind it.

-- Manuel Hermenegildo

------------------------------

Date: Sun 19 Jul 87 15:52:06-PDT
From: Chuck Restivo  <Restivo@Sushi.Stanford.EDU>
Subject: WARPLAN

D.Warren's WARPLAN is available from sushi.stanford.edu: as
ps:<prolog>warplan.pl via anonymous FTP.

------------------------------

End of PROLOG Digest
********************