NAME
Language::XSB - use XSB from Perl.
SYNOPSIS
use Language::XSB ':query';
use Language::Prolog::Types::overload;
use Language::Prolog::Sugar vars=>[qw(X Y Z)],
functors=>{equal => '='},
functors=>[qw(is)],
chains=>{plus => '+',
orn => ';'};
xsb_setquery( equal(X, 34),
equal(Y, -12),
is(Z, plus( X,
Y,
1000 )));
while(xsb_next()) {
printf("X=%d, Y=%d, Z=%d\n", xsb_result())
}
print join("\n", xsb_findall(orn(equal(X, 27),
equal(X, 45))));
ABSTRACT
Language::XSB provides a bidirectional interface to XSB (http://xsb.sourceforge.net).
DESCRIPTION
From the XSB manual:
XSB is a research-oriented Logic Programming and Deductive
Database System developed at SUNY Stony Brook. In addition to
providing all the functionality of Prolog, it contains
features not usually found in Logic Programming Systems such
as evaluation according to the Well Founded Semantics through
full SLG resolution, constraint handling for tabled programs,
a compiled HiLog implementation, unification factoring and
interfaces to other systems such as ODBC, C, Java, Perl, and
Oracle
This package implements a bidirectional interface to XSB, thats means that Perl can call XSB that can call Perl back that can call XSB again, etc.:
Perl -> XSB -> Perl -> XSB -> ...
(Unfortunately, you have to start from Perl, XSB->Perl->...
is not possible.)
The interface to XSB is based on the objects created by the package Language::Prolog::Types. You can also use Language::Prolog::Sugar package, a front end for the types package to improve the look of your source (just some syntactic sugar).
To make queries to XSB you have to set first the query term with the function xsb_setquery
, and then use xsb_next
and xsb_result
to iterate over it and get the results back.
Only one query can be open at any time, unless when Perl is called back from XSB, but then the old query is not visible.
EXPORT_TAGS
In this versions there is only one tag to import all the soubrutines in your script or package:
:query
-
xsb_setquery(@terms)
-
sets the query term, if multiple terms are passed, then the are first chained with the ','/2 functor and the result stored as the query.
It returns the free variables found in the query.
xsb_query()
-
returns the current query, variables are bound to its current value if
xsb_next
has been called with success. xsb_next()
-
iterates over the query and returns a true value if a new solution is found.
xsb_result()
-
after calling xsb_next, this soubrutine returns the values assigned to the free variables in the query.
xsb_cut()
-
ends an unfinished query, similar to XSB (or Prolog) cut
!
. As the real cut in XSB, special care should be taken to not cut over tables. xsb_findall(@terms)
-
does it all in one call (set the query, iterate over it and return a list of lists with the results found).
xsb_clearquery()
-
an alias for
xsb_cut
.
BUGS
This is alpha software so there should be some of them.
clpr is not callable from Perl, an FPE signal will raise.
no threads support.
SEE ALSO
Language::Prolog::Types, Language::Prolog::Types::overload and Language::Prolog::Sugar for instructions on creating Prolog (or XSB) terms from Perl.
For XSB and Prolog information see xsb(1), the XSB website at Sourceforge, the FAQ of comp.lang.prolog and any good Prolog book, I personally recommend you Ivan Bratko "PROLOG Programming for Artificial Intelligence" as an introduction to Prolog.
If you want to look at the inners details of this package then take a look at Language::XSB::Base and Language::XSB::Register.
AUTHOR
Salvador Fandiño, <sfandino@yahoo.com>
COPYRIGHT AND LICENSE
Copyright 2002 by Salvador Fandiño
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 306:
Non-ASCII character seen before =encoding in 'Fandiño,'. Assuming CP1252