AI-Prolog

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

use ExtUtils::MakeMaker;
use ExtUtils::MakeMaker qw/WriteMakefile prompt/;

my ( @program, @extra_modules );
print <<"END_NOTE";

The 'aiprolog' shell is optional.  If you choose to install it, Term::ReadLine
and Term::ReadKey will be added to your list of prerequisites.

END_NOTE

if (prompt( "Do you wish to install the 'aiprolog' shell?", "y" ) =~ /^[Yy]/ )
{
    @program = ( EXE_FILES => ["bin/aiprolog"] );
    @extra_modules = (
        'Term::ReadLine' => 1.01,
        'Term::ReadKey'  => 2.21,
    );
}

WriteMakefile(
    'NAME'         => 'AI::Prolog',

bin/aiprolog  view on Meta::CPAN


C<aiprolog> is a simple prolog shell using L<AI::Prolog> as the backend.

See the documentation for more detail on the Prolog features that L<AI::Prolog>
currently accepts.

=head2 Commands

Commands specific to aiprolog shell:

 "% more"     -- enables prompting for more results (default)
 "% no more"  -- disables prompting for more results
 "% nomore"   -- same as "no more"
 "% halt"     -- stops the shell
 "% help"     -- display this message

Note that the percent sign must preceed the command.  The percent sign
indicates a Prolog comment.  Without that, aiprolog will think you're trying to
execute a prolog command.

aiprolog-specific commands are case-insensitive.

bin/aiprolog  view on Meta::CPAN

 append([W|X], Y, [W|Z]) :- append(X,Y,Z).

Then load it into the C<aiprolog> shell by typing this at a shell:

 aiprolog path/to/append.pro

Alternatively, once in the shell, you can load the program with:

 consult('path/to/append.prog').

In the shell, you should be greeted by a query prompt "?-".  At this prompt,
you can issue queries against the program.  Try entering the following query:

 append(X,Y,[1,2,3,4]).

The shell should respond with this:

 append([],[1,2,3,4],[1,2,3,4]) ;

It should then appear to hang.  It's waiting for you to type a character.  If
you type a semi-colon, it will attempt to resatisfy the query.  If you keep

data/spider.pro  view on Meta::CPAN

        alive(spider),
        at(ruby, in_hand),
        print('The spider sees you with the ruby and attacks!!!'), nl,
        print('    ...it is over in seconds....'), nl,
        die.

describe(cave) :-
        alive(spider),
        print('There is a giant spider here!  One hairy leg, about the'), nl,
        print('size of a telephone pole, is directly in front of you!'), nl,
        print('I would advise you to leave promptly and quietly....'), nl.

describe(cave) :-
        print('Yecch!  There is a giant spider here, twitching.'), nl.

describe(spider) :-
        alive(spider),
        print('You are on top of a giant spider, standing in a rough'), nl,
        print('mat of coarse hair.  The smell is awful.'), nl.

describe(spider) :-

lib/AI/Prolog/Article.pod  view on Meta::CPAN

Now that we have a rough understanding of facts and rules, we need to know how
to get answers from them.  Queries are typically entered in the "interactive
environment." This would be analogous to the query window in a database GUI.
With C<AI::Prolog>, a shell named C<aiprolog> is included for demonstration
purposes though we'll mainly focus on calling Prolog from within a Perl
program.

 ?- gives(tom, book, SOMEONE).

This looks just like a fact, but with some minor differences.  The C<?-> at the
beginning of the query is a query prompt seen in interactive environments.

You'll also note that C<SOMEONE> is capitalized, making it a variable (only the
first letter needs to capitalized.)  Thus, this query is asking who Tom will
gives books to.

 ?- gives(WHO, book, SOMEONE).

This query looks like the previous one, but since the first argument is
capitalized, we're asking "who will give books to whom?".



( run in 1.408 second using v1.01-cache-2.11-cpan-6aa56a78535 )