AI-Prolog

 view release on metacpan or  search on metacpan

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

 % 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
the period is interpreted as the end of a clause.  The following is therefore a
syntax error:

 X is 5. + 7.

Unfortunately, the parser doesn't yet yell about that.  We'll try and figure
out why later.

Omit the period after the number or put a zero after it:

 X is 5.0 + 7.
 X is 5 + 7.

Because numbers use Perl scalars, you may mix types (ints and floats) and they
will behave as you expect in Perl.

Precedence is C<*> and C</>, left to right, followed by C<+> and C<->, left to
right followed by C<%>, left to right.  (I probably should change that.)
Naturally, parentheses may be used for grouping:

 X is 3 * 5 + 2.   % is(X, plus(mult(3, 5), 2)).
 X is 3 * (5 + 2). % is(X, mult(3, plus(5, 2))).

When using math, note that C<is> is similar to Perl's assignment operator, C<=>.
This can be confusing.

 X is 3 + 2.

Sets C<X> to the value of C<5>.  

If C<X> is already instantiated, this goal succeeds if the value of C<X> is the
value of the result of the right-hand side of the equation.  Internally, if X is not
instantiated, it looks like this:

 is(5, plus(3,2)).

The C<=> operator tries to unify the left-hand side with the right-hand side:

 X = 3 + 2.

If C<X> is already instantiated, this goal succeeds if the value of C<X> is the
same goal as the right-hand side of the equation.  Internally, if X is not
instantiated, it looks like this:

 eq(plus(3,2), plus(3,2)).

When you first start using Prolog, you probably was C<is> instead of C<=>.

Logical comparisons are straightforward:

 3 >= X.
 Y > (4 + 3) * X.
 X == Y. % a test for equality
 X \= Y. % Not equal.  See caveats for ne/2
 % etc.

=head1 BUGS

None known.

=head1 SEE ALSO

L<AI::Prolog::Introduction>

L<AI::Prolog>

W-Prolog:  L<http://goanna.cs.rmit.edu.au/~winikoff/wp/>

X-Prolog:  L<http://www.iro.umontreal.ca/~vaucher/XProlog/>

Roman BartE<225>k's online guide to programming Prolog:
L<http://kti.ms.mff.cuni.cz/~bartak/prolog/index.html>

=head1 AUTHOR

Curtis "Ovid" Poe, E<lt>moc tod oohay ta eop_divo_sitrucE<gt>

Reverse the name to email me.

This work is based on W-Prolog, http://goanna.cs.rmit.edu.au/~winikoff/wp/,
by Dr. Michael Winikoff.  Many thanks to Dr. Winikoff for granting me
permission to port this.

=head1 COPYRIGHT AND LICENSE

Copyright 2005 by Curtis "Ovid" Poe

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. 

=cut



( run in 2.141 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )