[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Feb 7 16:06:33 1993 
Subject:Prolog library(tracer) minor bug in V14.2 
From:Aaron Sloman 
Volume-ID:930207.01 

Although this newsgroup is not about prolog, many of its readers
will have Poplog, so here's some information about a minor bug
in a library supplied with Poplog Prolog.

Not everyone knows about Chris Mellish's beautiful prolog tracer which
is in the Poplog Prolog library as library(tracer).
(See PLOGHELP TRACER).

In Poplog V14.2 a minor bug crept in because fast_bagof was "fixed" in
the prolog system to return results in the "proper" order, and the
corresponding change was not made in the tracer library.

Anyone looking after a Poplog system can fix the tracer bug in the file

	$usepop/pop/plog/lib/tracer.pl

Replace lines 185-6

   fast_bagof((Patt:-Body),clause(Patt,Body),List),
   rev(List,Clauses),

with one line

   fast_bagof((Patt:-Body),clause(Patt,Body),Clauses),

also the definition of "rev" (lines 973-7) can now be removed as it is
not needed.

If you wish to try it out use the following examples, which I find are
very good for teaching beginners how Prolog works, in conjunction with
the Mellish tracer. (The tracer is not so good for normal debugging
because it is not controllable enough, but that could probably be
changed: for teaching it is superb.).

;;; load Mellish tracer if necessary.
?-library(tracer).

;;; For each of the following examples, use load marked range in VED
;;; then run the question. Beforehand do "ENTER trace" to turn on
;;; tracing

;;; Example 1.
;;; Family example -- define the grandfather relation.
pa(tom,dick).
pa(dick,joe).
pa(dick,mary).
ma(mary,fred).

grandpa(X,Y):-pa(X,Z),pa(Z,Y).
grandpa(X,Y):-pa(X,Z),ma(Z,Y).

;;; grandpa question (ask for more answers using ";" at end)
?- grandpa(X,Y).


;;; Example 2 showing datastructures being created
;;; House example.
bedroom(room1).
bedroom(room2).
bedroom(room3).
bathroom(bathroom1).
kitchen(kitchen1).
kitchen(kitchen2).
lounge(lounge1).
hall(hall1).

house(X,Y) :-
	topfloor(X),groundfloor(Y).

topfloor(rooms(A,B,C)) :-
	bedroom(A),	bedroom(B),	A \= B,	bathroom(C).

groundfloor(rooms(A,B,C)) :-
	kitchen(A), lounge(B), hall(C).


;;; Question, how to build a house (more than one design possible).
?-house(P,Q).


;;; Example 3 replace elements of a list and build a new list
;;; Demonstrates recursion (Thanks to Helen Gaylard for suggesting
;;; this.)

replace(_, _, [],[]).
replace(Old, New, [Old|L] ,[New|L1]):-
    replace(Old, New, L, L1).
replace(Old, New, [Z|L], [Z|L1]):-
    Z \= Old,
    replace(Old, New, L, L1).


;;; Now replace "a" with "b" in a list. Result for X should be [b,2,b,4]
;;; or equivalently [b|[2|[b|[4|[]]]]]

?-replace(a,b,[a,2,a,4],X).

;;; watch how the list is built up on the top line of the trace.


;;; Example 4. As above, but with cut.
;;; Replace second rule for replace with

replace(Old, New, [Old|L] ,[New|L1]):-
    replace(Old, New, L, L1),
    !.

;;; Then redo the test, and watch how backtracking past the cut
;;; works.

Aaron
-- 
Aaron Sloman,
School of Computer Science, The University of Birmingham, B15 2TT, England
EMAIL   A.Sloman@cs.bham.ac.uk  OR A.Sloman@bham.ac.uk
Phone: +44-(0)21-414-3711       Fax:   +44-(0)21-414-4281