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

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

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

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

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

Language::Prolog::Yaswi will release the engine when the script finish, this function is usefull to release the engine to free resources or to be able to init it again with a different set of arguments.

To get a Perl object passed to prolog as an opaque value instead of marshaled into prolog types, its class (or one of its parent classes) has to be previously registered as opaque with the $swi_converter object. i.e.:

To get thread support in this module both Perl and SWI-Prolog have to be previously compiled with threads. Perl needs the ithread model available from Perl version 5.8.0 and upwards.

When Perl is called back from a thread created from Prolog a new fresh Perl engine is constructed. That means there will be no modules preloaded on it, no access to Perl data from other threads (not even data marked as shared!), etc. Threads created from Perl do not suffer from this limitation.