% 
%  Runable Notes and Tutorial
%  $Id: tut.P,v 1.2 2001/04/24 19:52:30 sandro Exp $
%
%  - XSB is on tux, and downloadable from
%    http://sourceforge.net/project/showfiles.php?group_id=1176
%
%  - XSB Documentation
%    http://xsb.sourceforge.net/manual1/index.html
%    http://xsb.sourceforge.net/manual2/index.html
%    
%  - Prolog Tutorials, such as:
%    http://cbl.leeds.ac.uk/~tamsin/prologtutorial/
%
%  Go to a personal directory and type:
%      cp ~sandro/tut.P .                        # ENTRY 1
%  or  cvs checkout WWW/2001/04/pl/tut.P; cd WWW/2001/04/pl/ 
%      xsb -e '[tut].'                           # ENTRY 2
%  then enter queries...
%

% enable XSB smarts 
:- auto_table.

% enable XSB rewriting to support pseudo-higher-order logic
:- hilog dog,cat,mouse,canary,eagle,bear,mammal.

% some simple facts for the database...
dog(spot).
dog(rover).
cat(tom).
mouse(jerry).
canary(tweety).
eagle(sam).
bear(wally).
bear(rover).

% some others....
brother(spot, rover).
age(spot, 3).
age(rover, 5).
relationship(friend, spot, rover).
relationship(enemy, jerry, spot, rover).

% try these queries....
%   dog(rover).                                % ENTRY 3
%   dog(tom).                                  % ENTRY 4
%   dog(X).                                    % ENTRY 5
%            -- use RETURN to say that's right
%            -- use SEMI-COLON to say that's not right (try again)
%            [ Note that extra-spaces at the end of the query line
%              introduce some bug here. ]
%   dog(X), bear(X).                           % ENTRY 6

% a rule...
mammal(X) :- dog(X).
mammal(X) :- cat(X).
mammal(X) :- mouse(X).
mammal(X) :- bear(X).

% some queries...
%   mammal(X).                                % ENTRY 7

% a higher-order logic rule...
species(S, X) :- 
   S(X).

% some queries...
%   species(dog, X).                         % ENTRY 8
%   species(Spec, Anim).                     % ENTRY 9 (error)

% map to an RDF  form....
property(Class, 'foo:instance', Instance) :-
   Class(Instance).

%
% This might be nice, but doesn't work....
%
%   property(dog, 'foo:instance', spike).
%
%   Class(Instance) :-
%      property(Class, 'foo:instance', Instance).
%

% Dynamic changes to the database

%  assert(dog(spike)).                      % ENTRY 10
%  dog(X).                                  % ENTRY 11
%  retract(dog(spike)).                     % ENTRY 12
%  dog(X).                                  % ENTRY 13

% Which is a special case of side-effects (IMPURE prolog), which
% us most clearly seen in this non-database, impure kind of thing.

%  writeln('Hello, World!').                % ENTRY 14

%  mammal(X), writeln(X),  fail.            % ENTRY 15

