Hi,
Ovid wrote:
--- Salvador Fandiņo <[EMAIL PROTECTED]> wrote:
I have uploaded to CPAN version 0.07 of Language::Prolog::Yaswi, an interface to SWI-Prolog.
I have also released DBD::Yaswi, an experimental DBI interface to SWI-Prolog. I am not completely sure if this module is a real improvement over the raw Language::Prolog::Yaswi... well, comments are welcome!!!
Hi Salvador,
It's great to see stuff happening with this again!
When I first tried to isntall DBD::Yaswi, I got: ...
DBD::Yaswi has to be registered on the DBI module, Tim Bunce (the DBI author) have accepted to do it, but has not released a new DBI yet.
You can modify your local DBI.pm:
Look for the registry hash $dbd_prefix_registry definition and add an entry for DBD::Yaswi at the end as...
yaswi_ => { class => 'DBD::Yaswi', },
then it should work.
Also, from the docs, it's not clear how to build a database or issue queries against it. So let's say I want to find all X and Y that satisfy append/3, would I do something like this?
my $dbh = DBI->connect('dbi:Yaswi:user'); my $sth = $dbh->prepare(<<'END_PROLOG'); find [X,Y] where Z=[a,b,c,d], \ append([],X,X). \ append([W|X],Y,[W|Z]) :- append(X,Y,Z). END_PROLOG
From your docs and the tests, that doesn't seem right.
Can I load a pre-existing prolog program, call assert, retract, etc?
You can freely mix calls to Language::Prolog::Yaswi and DBD::Query, the only requirement is to not let queries open from one module when calling the other (calling finish() on open DBD::Yaswi queries or swi_cut on the Language::Prolog::Yaswi side).
There are new functions to consult files swi_consult() function to consult files, i.e:
swi_consult qw(foo, bar) swi_use_modules qw(foo, bar)
and the swi_inline function to consult inline modules.
swi_inline <<PROLOG; append([], X, X). append([W|X],Y,[W|Z]) :- append(X,Y,Z). PROLOG
DBD::Yaswi can be extended via the multifile predicate dbd:dbd_map_query/3.
I have included support for two simple operations, "find" and "insert", just for experimentation, but others can be easyly added, for example "consult":
$db=DBI->connect('dbi:Yaswi:user')
# and then, always after the connect call to ensure that # DBD::Yaswi has been loaded (or alternatively, loading # DBD::Yaswi explicitly):
swi_inline << PROLOG; dbd:dbd_map_query(consult(X), consult(X), []). PROLOG
$db->do('consult(foo)')
or even
$sth_consult=$db->prepare('consult(?)')
for (qw(foo bar doo) ) { $sth_consult->execute($_) }
I know module documentation is poor, but I have not really made my mind yet about the right query language for DBD::Yaswi... and anyway, the code is available and it is also a good example of how to use Language::Prolog::Yaswi ;-)
Cheers,
- Salvador