Re: [ANN] Language::Prolog::Yaswi and DBD::Yaswi
[email protected] (Salvador FandiƱo) Tue, 22 Feb 2005 18:04:27 +0000
| Newsgroups | perl.ai |
|---|---|
| Message-ID | <[email protected]> |
Hi, Ovid wrote: > --- Salvador Fandi=F1o <[email protected]> wrote: >=20 >>I have uploaded to CPAN version 0.07 of Language::Prolog::Yaswi,=20 >> an interface to SWI-Prolog. >> >>I have also released DBD::Yaswi, an experimental DBI interface to=20 >>SWI-Prolog. I am not completely sure if this module is a real=20 >>improvement over the raw Language::Prolog::Yaswi... well,=20 >>comments are welcome!!! >=20 >=20 > Hi Salvador, >=20 > It's great to see stuff happening with this again! >=20 > When I first tried to isntall DBD::Yaswi, I got: =20 > ... DBD::Yaswi has to be registered on the DBI module, Tim Bunce (the=20 DBI author) have accepted to do it, but has not released a new=20 DBI yet. You can modify your local DBI.pm: Look for the registry hash $dbd_prefix_registry definition and=20 add an entry for DBD::Yaswi at the end as... yaswi_ =3D> { class =3D> '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 =3D DBI->connect('dbi:Yaswi:user'); > my $sth =3D $dbh->prepare(<<'END_PROLOG'); > find [X,Y] where Z=3D[a,b,c,d], \ > append([],X,X). \ > append([W|X],Y,[W|Z]) :- append(X,Y,Z). > END_PROLOG >=20 > From your docs and the tests, that doesn't seem right. >=20 > Can I load a pre-existing prolog program, call assert, retract, etc? You can freely mix calls to Language::Prolog::Yaswi and=20 DBD::Query, the only requirement is to not let queries open from=20 one module when calling the other (calling finish() on open=20 DBD::Yaswi queries or swi_cut on the Language::Prolog::Yaswi side). There are new functions to consult files swi_consult() function=20 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=20 dbd:dbd_map_query/3. I have included support for two simple operations, "find" and=20 "insert", just for experimentation, but others can be easyly=20 added, for example "consult": $db=3DDBI->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=3D$db->prepare('consult(?)') for (qw(foo bar doo) ) { $sth_consult->execute($_) } I know module documentation is poor, but I have not really made=20 my mind yet about the right query language for DBD::Yaswi... and=20 anyway, the code is available and it is also a good example of=20 how to use Language::Prolog::Yaswi ;-) Cheers, - Salvador