[comp.lang.prolog] prolog tutorial seattle

bimbart@kulcs.uucp (Bart Demoen) (09/06/88)

Tutorial No:8 of LP'88 Seattle (R. O'Keefe) makes 'interesting' reading, but
be careful: some topics depend heavely on the Prolog system at hand;
here is an example:

Section 9 p.107 is about meta-interpreters that can handle the ! cut.
The proposal is to represent clauses as

	rule(Head,Goals_before_cut,Cut,Goals_after_cut) .

and base the interpreter on this representation.
This only works if the ! inside the metacall (call/1) does not cut outside
the metacall, and that's something implementations do not agree on.

bimbart@kulcs.uucp
Bart Demoen
Dept. of Computer Science
Celestijnenlaan 200A
B-3030 Leuven
Belgium

bimbart@kulcs.uucp (Bart Demoen) (09/06/88)

Tutorial No:8 of LP'88 Seattle (R. O'Keefe) makes 'interesting' reading and
even contains some self-referential jokes; read this quotation from section 12.6
p.141 (it is about a Prolog program that follows immediatly after the quotation)

	'This code has been tested in Quintus Prolog, and works.'

So, what should we think about the other programs in the tutorial ?

Or perhaps this was a serious comment, since if you try to run findall_5 (p.151)
or findall (p.152) as they stand ... trouble !

bimbart@kulcs.uucp
Bart Demoen
Dept. of Computer Science
Celestijnenlaan 200A
B-3030 Leuven
Belgium

ok@quintus.uucp (Richard A. O'Keefe) (09/07/88)

In article <1429@kulcs.kulcs.uucp> bimbart@kulcs.UUCP (Bart Demoen) writes:
>Tutorial No:8 of LP'88 Seattle (R. O'Keefe) makes 'interesting' reading, but
>be careful: some topics depend heavily on the Prolog system at hand;
>here is an example:

Surely someone has told Demoen by now that calling something "'interesting'"
is about 10 times more insulting than calling it "trash"?

The *topic* in question doesn't depend on the Prolog system at all,
the *code* in one of the *examples* may perhaps fail to work in some systems.

>Section 9 p.107 is about meta-interpreters that can handle the ! cut.
>The proposal is to represent clauses as

>	rule(Head,Goals_before_cut,Cut,Goals_after_cut) .

>and base the interpreter on this representation.
>This only works if the ! inside the metacall (call/1) does not cut outside
>the metacall, and that's something implementations do not agree on.

I cannot follow this.  The interpreter in question does not call the
built-in call/1 predicate!  Here is the code:

	prove(Goal) :-
		rule(Goal, Before, Cut, After),	% Cut is 0 or 1
		prove_body(Before),
------------>	( Cut =:= 1 -> ! ; true ),
		prove_body(After).

	prove_body([]).
	prove_body([Goal|Goals]) :-
		prove(Goal),
		prove_body(Goals).

THERE IS NO META-CALL HERE!  There _is_ a cut inside an if->then;else,
but I went to some trouble about four years ago to explain on the net
(a) that cut is supposed to cut through disjunctions, and
(b) why that is useful, and
(c) how to write a Prolog interpreter using this feature.
The ALS Prolog manual says that their debugger is based on that
interpreter, so I'm pretty sure ALS Prolog gets cuts in disjunctions right!

The code as written would not work in DEC-10 Prolog, because the 
DEC-10 Prolog compiler did not understand (If->Then;Else) -- though
the interpreter did -- but the conditional cut can be written as
		( Cut =:= 1, ! ; true )
in DEC-10 Prolog or in any Prolog whose implementors have made a
genuine attempt to be "Edinburgh-compatible".  (Even C Prolog, which
_does_ handle if->then;else with a sort of meta-call, gets this right.)

I have not been able to tell from the old VM/Programming in Logic manual
that I have access to whether this would work in VM/PROLOG or not, but
if not, the variant

	PROVE(*GOAL) <-
		LABEL(PROVE_MARKER) &
		RULE(*GOAL, *BEFORE, *CUT, *AFTER) &
		PROVE_BODY(*BEFORE) &
		( *CUT = 1 & CUT(PROVE_MARKER) | TRUE ) &
		PROVE_BODY(*AFTER).

would do.  I cannot tell from the old BIM_Prolog manual I have access
to whether BIM_Prolog gets this right or not (since the Edinburgh
convention is that (If->Then;Else) is bracketed as ;(->(If,Then);Else)
but the BIM convention is ->(If,;(Then,Else)) there is at least one
difference) but in the extremely unlikely event that BIM were
inadvertently offering a system for sale which had this possible
incompatibility the old manual describes two commands which could be
used to jury-rig a similar repair:

	prove(_goal) :-
		mark(137),	% pick a magic integer
		rule(_goal, _before, _cut, _after),
		prove_body(_before),
		(_cut =:= 1 -> (cut(137) ; true)),
		prove_body(_after).

I have not been able to try this, and have based this code on an old
version of the manual.  No fee, no guarantee!

ok@quintus.uucp (Richard A. O'Keefe) (09/07/88)

In article <1430@kulcs.kulcs.uucp> bimbart@kulcs.UUCP (Bart Demoen)
continues his 'kind', 'informative', and 'disinterested' comments:

>Tutorial No:8 of LP'88 Seattle (R. O'Keefe) makes 'interesting' reading and
>even contains some self-referential jokes; read this quotation from section 12.6
>p.141 (it is about a Prolog program that follows immediatly after the quotation)
>
>	'This code has been tested in Quintus Prolog, and works.'
>
>So, what should we think about the other programs in the tutorial?

Sob, sob, all these years I've been thinking that I had a sense of humour,
and now the sham is exposed.  I really don't see anything funny in that
sentence, especially as it precedes
	- the longest single chunk of code in the text
	- the chunk which is least "intuitive" or "Prolog-like"
	- the chunk which is least well backed up by the text.
	  (the text doesn't go through it clause-by-clause or even
	  predicate-by-predicate).
Is a reassurance that the thing has been observed to work (even though it
is not explained in detail) really out of place?

What are you to think about the other fragments?  Well, if you read the
rest of the text, you'll find in section "Conditional Reading" of
chapter "Using term_expansion/2" the sentence

	This code, like all the concrete code in this text,
	has been tested in Quintus Prolog, and works.

I *wonder* why Demoen didn't quote that sentence when he asked his
rhetorical question?  (There are at least two possibilities.)
[I have now amended this sentence to read "and appeared to work" (:-).]

I'm glad I said "the <concrete> code", because a typo has been found by
two people in the description of <method3> in section "Counters" of
chapter "Basic Topics": "<method3>(M, U, -args-)" should read
"<method3>(N, U, -args-)".

>Or perhaps this was a serious comment, since if you try to run findall_5 (p.151)
>or findall (p.152) as they stand ... trouble!

Demoen would do all of us a service if, in his criticisms, he would take the
trouble to go into detail.  The correct code of findall_5/3 is

findall_5(Template, Generator, List) :-
	asserta('find all'([]), MarkRef),
	(   call(Generator),
	    asserta('find all'(Template)),
	    fail
	;   'all found'(MarkRef, [], List)
	).

I do not have a copy of the tutorial as it was printed for the conference,
so I'm not sure if this is what Demoen is talking about, but there was a
draft where the code of findall_5/3 and findall/3 had been reindented to
make them look more like the code of findall_4/3, and that had introduced
a mistake.  findall_5/3 and findall/3 should have the shape shown above,
where the first asserta/2 is outside the disjunction.  The text includes
times for several versions of findall; the times refer to the original
correct code.  Needless to say, the times *are* system-dependent.

Lesson for authors: having introduced machine-readable source code into
your text, *don't* try to make it look nicer!