AI-Prolog
view release on metacpan or search on metacpan
data/sleepy.pro view on Meta::CPAN
/* "Sleepy" -- a sample adventure game, by David Matuszek. */
% http://www.csc.vill.edu/~dmatusze/resources/prolog/sleepy.html
/* In standard Prolog, all predicates are "dynamic": they
can be changed during execution. SWI-Prolog requires such
predicates to be specially marked. */
% :- dynamic at/2, i_am_at/1, i_am_holding/1, alive/1,
% lit/1, visible_object/1.
/* This routine is purely for debugging purposes. */
%dump :- listing(at), listing(i_am_at), listing(i_am_holding),
% listing(alive), listing(lit), listing(visible_object).
/* This defines my current location. */
i_am_at(bedroom).
i_am_holding(nothing).
data/sleepy.pro view on Meta::CPAN
/* Have flyswatter, room is lit, fly is here and alive. */
swat :-
buzz_off,
print('The fly escapes into the other room.'), nl.
swat :-
print('Success! You killed that pesky fly!'), nl,
retract(alive(fly)).
swat :- /* For debugging... */
print('You must have forgotten a case!', nl).
make_visible(X) :-
visible_object(X).
make_visible(X) :-
assert(visible_object(X)).
buzz_off :-
at(fly, bedroom),
lib/AI/Prolog/Builtins.pod view on Meta::CPAN
=back
=head1 MATH
Since version .70, math is fully available in C<AI::Prolog>. Note that math is
implemented via the
L<AI::Prolog::Parser::PreProcessor::Math|AI::Prolog::Parser::PreProcessor::Math>
module. This module rewrites Prolog math to an internal, predicate-based form
with the L<AI::Prolog::Parser|AI::Prolog::Parser> can parse. This may cause
confusion when debugging.
X is 5 + 7.
% internally converted to
% is(X, plus(5, 7)).
The math predicates are officially deprecated and I<cannot> be used in the same
expression with regular Prolog math.
Number may be integers, floats, doubles, etc. A number that starts with a
minus sign (-) is considered negative. No number may end in a decimal point as
lib/AI/Prolog/Parser.pm view on Meta::CPAN
package AI::Prolog::Parser;
$REVISION = '$Id: Parser.pm,v 1.9 2005/08/06 23:28:40 ovid Exp $';
$VERSION = '0.10';
use strict;
use warnings;
use Carp qw( confess croak );
use Regexp::Common;
use Hash::Util 'lock_keys';
# debugging stuff
use Clone;
use Text::Balanced qw/extract_quotelike extract_delimited/;
use aliased 'AI::Prolog::Engine';
use aliased 'AI::Prolog::KnowledgeBase';
use aliased 'AI::Prolog::Parser::PreProcessor';
use aliased 'AI::Prolog::Term';
use aliased 'AI::Prolog::Term::Number';
use aliased 'AI::Prolog::TermList';
use aliased 'AI::Prolog::TermList::Clause';
lib/AI/Prolog/Term.pm view on Meta::CPAN
return $self->ref->occurs1($var) if $self->{deref};
for my $i ( 0 .. $self->arity - 1 ) {
return 1 if $self->{args}[$i]->occurs1($var);
}
}
else {
return $self->varid == $var;
}
}
# used internally for debugging
sub _dumpit {
local $^W;
my $self = shift;
my $indent = shift || '';
print( $indent . "source: ", $self->{source} );
print( $indent . "bound: ", ( $self->{bound} ? 'true' : 'false' ) );
print( $indent . "functor: ", ( $self->{functor} || 'null' ) );
if ( !$self->{ref} ) {
print( $indent . "ref: null" );
}
lib/AI/Prolog/TermList.pm view on Meta::CPAN
$self->{next} = shift;
return $self;
}
return $self->{next};
}
sub next_clause {
my $self = shift;
if (@_) {
# XXX debug
my $next_clause = shift;
no warnings 'uninitialized';
if ( $next_clause eq $self ) {
confess("Trying to assign a termlist as its own successor");
}
$self->{next_clause} = $next_clause;
return $self;
}
return $self->{next_clause};
}
lib/AI/Prolog/TermList/Step.pm view on Meta::CPAN
1;
__END__
=head1 NAME
AI::Prolog::TermList::Step - Perl implementation of Prolog "step" mechanism.
=head1 SYNOPSIS
No user serviceable parts inside. You should never be seeing this. This is
a debugging tool.
=head1 DESCRIPTION
See L<AI::Prolog|AI::Prolog> for more information. If you must know more,
there are plenty of comments sprinkled through the code.
=head1 SEE ALSO
L<AI::Prolog>
( run in 1.380 second using v1.01-cache-2.11-cpan-49f99fa48dc )