-----BEGIN PGP SIGNED MESSAGE-----
Hash: MD5

Hi Salvador,

Looks very interesting, but if it is an interface to
a specific prolog, shouldn't it all be in a namespace
reflecting that?

Like Language::Prolog::SWI, rather than just Language::Prolog?

lee

On Wednesday, January 22, 2003 at 4:09:06 PM, you wrote:

SF> NAME
SF>     Language::Prolog::Yaswi - Yet another interface to
SF> SWI-Prolog

SF> SYNOPSIS
SF>       use Language::Prolog::Yaswi ':query';
SF>       use Language::Prolog::Types::overload;
SF>       use Language::Prolog::Sugar functors => { equal =>
SF> '='
SF>                                                 is    =>
SF> 'is' },
SF>                                   chains => { orn => ';',
SF>                                               andn => ',',
SF>                                               add => '+' },
SF>                                   vars => [qw (X Y Z)];

SF>       swi_set_query( equal(X, Y),
SF>                      orn( equal(X, 27),
SF>                           equal(Y, 'hello')));

SF>       while (swi_next) {
SF>           printf "Query=".swi_query()."\n";
SF>           printf "  X=%_, Y=%_\n\n", swi_var(X),
SF> swi_var(Y);
SF>       }

SF>       print join("\n",
SF>                  xsb_findall(andn(equal(X, 2),
SF>                                   orn(equal(Y, 1),
SF>                                       equal(Y, 3.1416))
SF>                                   is(Z, plus(X,Y,Y))),
SF>                              [X, Y, Z]);

SF> ABSTRACT
SF>     Language::Prolog::Yaswi implements a bidirectional
SF> interface to the
SF>     SWI-Prolog system (<http://www.swi-prolog.org/>).

SF> DESCRIPTION
SF>     This package provides a bidirectional interface to
SF> SWI-Prolog. That
SF>     means that Prolog code can be called from Perl that can
SF> call Perl code
SF>     again and so on:

SF>       Perl -> Prolog -> Perl -> Prolog -> ...

SF>     (unfortunately, by now, the cicle has to be started
SF> from Perl, although
SF>     it is very easy to circunvent this limitation with the
SF> help of a dummy
SF>     Perl script that just calls Prolog the first time).

SF>     The interface is based on the set of classes defined in
SF>     Language::Prolog::Types. Package
SF> Language::Prolog::Sugar can also be
SF>     used to improve the look and readability of scripts
SF> mixing Perl and
SF>     Prolog code.

SF>     The interface to call Prolog from Perl is very simple,
SF> at least if you
SF>     are used to Prolog non deterministic.

SF>   SUBROUTINES
SF>     Grouped by export tag:

SF>     ":query"

SF>         "swi_set_query($query1, $query2, $query3, ...)"
SF>             Compose a query with all its parameters and
SF> sets it. Return the
SF>             set of free variables found in the query.

SF>         "swi_set_query_module($query, $module,
SF> $ctx_module)"
SF>             Allows to set a query in a different module
SF> than the default.

SF>         "swi_result()"
SF>             Return the values binded to the variables in
SF> the query.

SF>         "swi_next()"
SF>             Iterates over the query solutions.

SF>             If a new solution is available returns true, if
SF> not, closes the
SF>             query and returns false.

SF>             It should be called after "swi_set_query(...)"
SF> to obtain the
SF>             first solution.

SF>         "swi_var($var)"
SF>             Returns the value binded to $var in the current
SF> query/solution
SF>             combination.

SF>         "swi_query"
SF>             Returns the current query with the variables
SF> binded to its
SF>             values in the current solution (or unbinded if
SF> swi_next has not
SF>             been called yet).

SF>         "swi_cut"
SF>             Closes the current query even if not all of its
SF> solutions have
SF>             been retrieved. Similar to prolog "!".

SF>         "swi_find_all($query, @pattern)"
SF>             iterates over $query and returns and array with
SF> @pattern binded
SF>             to every solution. i.e:

SF>               swi_find_all(member(X, [1, 3, 7, 21]), X)

SF>             returns the array "(1, 3, 7, 21)" and

SF>               swi_find_all(member(X, [1, 3, 7, 21]), [X])

SF>             returns the array "([1], [3], [7], [21])".

SF>             More elaborate constructions can be used:

SF>               %mothers=swi_find_all(mother(X,Y), X, Y)

SF>             There is also an example of its usage in the
SF> SYNOPSIS.

SF>         "swi_find_one($query, @pattern"
SF>             as "swi_find_all" but only for the first
SF> solution.

SF>         "swi_call"
SF>             runs the query once and return true if a
SF> solution was found or
SF>             false otherwise.

SF>     ":interactive"

SF>         "swi_toplevel"
SF>             mostly for debugging pourposes, runs SWI-Prolog
SF> shell.

SF>     ":assert"

SF>         "swi_assert($head => @body)"
SF>         "swi_assertz($head => @body)"
SF>             add new definitions at the botton of the
SF> database

SF>         "swi_asserta($head => @body)"
SF>             adds new definitions at the top of the database

SF>         "swi_facts(@facts)"
SF>             commodity subroutine to add several facts
SF> (facts, doesn't have
SF>             body) to the database in one call.

SF>             i.e.:

SF>               use Language::Prolog::Sugar functors=>[qw(man
SF> woman)];

SF>               swi_facts( man('teodoro'),
SF>                          man('socrates'),
SF>                          woman('teresa'),
SF>                          woman('mary') );

SF>     ":context"

SF>         $swi_module
SF>         $swi_ctx_module
SF>             allows to change the module and the context
SF> module for the
SF>             upcoming queries.

SF>             use ALWAYS the "local" operator when changing
SF> its value!!!

SF>             i.e.:

SF>                local $swi_module='mymodule'
SF>                swi_set_query($query_from_mymodule);

SF>         $swi_converter
SF>             allows to change the way data is converter from
SF> Perl to Prolog.

SF>             You should not use it for any other thing that
SF> to configure perl
SF>             classes as opaque, i.e.:


$swi_converter->>pass_as_opaque(qw(LWP::UserAgent

SF> HTTP::Request

SF> HTTP::Result))

SF>   CALLBACKS
SF>     Yaswi adds to SWI-Prolog three new predicates to call
SF> perl back.

SF>     All the calls are make in array contest and the Result
SF> value is always a
SF>     list. There is not way to make a call in scalar context
SF> yet.

SF>     "perl5_eval(+Code, -Result)"
SF>         makes perl evaluate the string "Code" (really a
SF> Prolog atom) and
SF>         returns the results.

SF>     "perl5_call(+Sub, +Args, -Result)"
SF>         calls a perl sub.

SF>     "perl5_method(+Object, +Method, +Args, -Result)"
SF>         calls the method "Method" from the perl object
SF> "Object".

SF>         To get objects passed to prolog as opaques instead
SF> of marshaled to
SF>         prolog types, its class (or one of its parent
SF> classes) has to be
SF>         previously register as opaque with the
SF> $swi_converter object. i.e.:


SF> perl5_eval('$swi_converter->pass_as_opaque("HTTP::Request")',_),
SF>           perl5_eval('use HTTP::Request',_),
SF>           perl5_method('HTTP::Request', new, [],
SF> [Request]),
SF>           perl5_method(Request, as_string, [], [Text]);

SF>         Registering class "UNIVERSAL" makes all objects to
SF> be passed to
SF>         prolog as opaques.

SF>   EXPORT
SF>     This module doesn't export anything by default.
SF> Subroutines should be
SF>     explicitely imported.

SF> SEE ALSO
SF>     SWI-Prolog documentation <http://www.swi-prolog.org/>,
SF>     Languages::Prolog::Types, Language::Prolog::Sugar

SF> AUTHOR
SF>     Salvador Fandiņo, <sfandino AT yahoo.com>

SF> COPYRIGHT AND LICENSE
SF>     Copyright 2003 by Salvador Fandiņo

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

-----BEGIN PGP SIGNATURE-----
Version: 2.6

iQCVAwUAPi7zN6drfekeF/QBAQFVNQQAswsGde50oVocGFzJ8/DqF8Kx7zqUFgJM
i1Me/dISdO3SFbMBYr81OiV089ajqA+ArAxcKDSA+hyU2sMVzmnogBkvDZVO2Vfx
J1xUhVwKeHVonzkS1pABX7FPNMNpHamRt0Xlvd7/ikmpkHQijLE/0405J2iw57N4
QBLvyeZC3hM=
=r4hU
-----END PGP SIGNATURE-----

Reply via email to