view release on metacpan or search on metacpan
examples/append.pl view on Meta::CPAN
#!/usr/local/bin/perl
use strict;
use warnings;
use lib ('../lib/', 'lib');
use Data::Dumper;
$Data::Dumper::Indent = 0;
$Data::Dumper::Terse = 1;
use AI::Prolog 0.64;
my $prolog = AI::Prolog->new(<<"END_PROLOG");
append([], X, X).
append([W|X], Y, [W|Z]) :- append(X, Y, Z).
END_PROLOG
examples/benchmark.pl view on Meta::CPAN
#!/usr/local/bin/perl
use strict;
use warnings;
use lib ('../lib/', 'lib/');
use Benchmark;
use AI::Prolog;
my $prolog = AI::Prolog->new(benchmark());
my $t0 = new Benchmark;
for (1 .. 10) {
$prolog->query('nrev30.');
while (my $result = $prolog->results) {
print $_,' ',@$result,$/;
}
examples/cut.pl view on Meta::CPAN
#!/usr/local/bin/perl -l
use strict;
use warnings;
use lib ('../lib/', 'lib');
use aliased 'AI::Prolog';
use aliased 'AI::Prolog::Engine';
my $prolog = Prolog->new(<<'END_PROLOG');
append([], X, X).
append([W|X],Y,[W|Z]) :- append(X,Y,Z).
END_PROLOG
Engine->formatted(1);
$prolog->query('append(X,Y,[a,b,c,d]).');
examples/data_structures.pl view on Meta::CPAN
#!/usr/local/bin/perl -l
use strict;
use warnings;
use lib ('../lib/', 'lib/');
use Data::Dumper;
$Data::Dumper::Indent = 0;
use AI::Prolog;
# note that the following line sets an experimental interface option
AI::Prolog->raw_results(0);
my $database = <<'END_PROLOG';
append([], X, X).
append([W|X],Y,[W|Z]) :- append(X,Y,Z).
examples/hanoi.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use lib ('../lib/', 'lib/');
use aliased 'AI::Prolog';
my $prolog = Prolog->new(<<'END_PROLOG');
hanoi(N) :-
move(N, left, center, right).
move(0, _, _, _) :- !.
move(N,A,B,C) :-
examples/if_else.pl view on Meta::CPAN
#!/usr/local/bin/perl -l
use strict;
use lib qw(../lib/ lib/);
use AI::Prolog;
use Data::Dumper;
$Data::Dumper::Terse = 1;
my $prolog = AI::Prolog->new(<<'END_PROLOG');
thief(badguy).
steals(PERP, X) :-
if(thief(PERP), eq(X,rubies), eq(X,nothing)).
END_PROLOG
$prolog->query("steals(badguy,X).");
examples/member.pl view on Meta::CPAN
#!/usr/local/bin/perl -l
use strict;
use warnings;
use lib ('../lib/', 'lib');
use aliased 'AI::Prolog';
my $prolog = Prolog->new(<<'END_PROLOG');
member(X,[X|Xs]).
member(X,[_|Ys]) :- member(X,Ys).
teacher(Person) :- member(Person, [randal,bob,sally]).
classroom(Room) :- member(Room, [class1,class2,class3]).
classtime(Time) :- member(Time, [morning_day1,morning_day2,noon_day1,noon_day2]).
END_PROLOG
examples/monkey.pl view on Meta::CPAN
#!/usr/local/bin/perl
# see http://www.compapp.dcu.ie/~alex/LOGIC/monkey.html
# This is the classic Monkey/Banana problem
use strict;
use warnings;
use lib ('../lib/', 'lib');
use AI::Prolog;
my $prolog = AI::Prolog->new(<<'END_PROLOG');
perform(grasp,
state(middle, middle, onbox, hasnot),
state(middle, middle, onbox, has)).
perform(climb,
state(MP, BP, onfloor, H),
state(MP, BP, onbox, H)).
examples/path.pl view on Meta::CPAN
#!/usr/local/bin/perl -l
use strict;
use warnings;
use lib ('../lib/', 'lib');
use AI::Prolog;
use Benchmark;
use Data::Dumper;
$Data::Dumper::Indent = 0;
my $query = shift || 2;
my $prolog = AI::Prolog->new(path_prog());
$prolog->query('solve( Dest, L).') if $query == 1;
$prolog->query('solve( p(8,8), L).') if $query == 2;
examples/schedule.pl view on Meta::CPAN
# There are 6 class periods, 6-8pm and 8-10pm on Monday, Wednesday, and Friday
# evenings. There are classrooms A, B, and C, and teachers Jim, Sally, Susan,
# and George. There are classes algebra, geometry, calculus, and analysis, each
# of which has to be taught 2 class periods per week. Jim can only come on
# Mondays. Sally and Susan want to work together. George can only teach the
# 6-8pm periods. Just write the program to print all possible schedules that meet
# these constraints; don?t try to solve the scheduling problem.
use strict;
use warnings;
use lib ('../lib/', 'lib/');
use aliased 'AI::Prolog';
my $prolog = Prolog->new(<<'END_PROLOG');
member(X,[X|Xs]).
member(X,[_|Ys]) :- member(X,Ys).
scheduler(L) :- makeList(L,4), different(L).
makeList([],0):- !.
examples/trace.pl view on Meta::CPAN
#!/usr/local/bin/perl -l
use strict;
use warnings;
use lib ('../lib/', 'lib/');
use aliased 'AI::Prolog';
AI::Prolog->raw_results(0); # experimental
my $logic = Prolog->new(thief_prog());
print "Without trace ...\n";
$logic->query('steals("Bad guy", STUFF, VICTIM)');
while (my $results = $logic->results) {
printf "Bad guy steals %s from %s\n",
$results->STUFF, $results->VICTIM;
}
t/05examples.t view on Meta::CPAN
#use Test::More 'no_plan';
use Test::More tests => 6;
my $CLASS;
BEGIN
{
chdir 't' if -d 't';
unshift @INC => '../lib';
}
use lib '../lib/';
use aliased 'AI::Prolog';
my $prolog = Prolog->new(append_prog());
$prolog->query("append(X,Y,[a,b,c,d]).");
AI::Prolog::Engine->formatted(1);
is $prolog->results, 'append([], [a,b,c,d], [a,b,c,d])', 'Running the prolog should work';
is $prolog->results, 'append([a], [b,c,d], [a,b,c,d])', '... as should fetching more results';
is $prolog->results, 'append([a,b], [c,d], [a,b,c,d])', '... as should fetching more results';
is $prolog->results, 'append([a,b,c], [d], [a,b,c,d])', '... as should fetching more results';