Did you know ... | Search Documentation: |
library(pengines): Pengines: Web Logic Programming Made Easy |
The library(pengines)
provides an infrastructure for
creating Prolog engines in a (remote) pengine server and accessing these
engines either from Prolog or JavaScript.
Remaining options are passed to http_open/3 (meaningful only for non-local pengines) and thread_create/3. Note that for thread_create/3 only options changing the stack-sizes can be used. In particular, do not pass the detached or alias options..
Successful creation of a pengine will return an event term of the following form:
An error will be returned if the pengine could not be created:
Options is a list of options:
false
, the Pengine
goal is not executed using findall/3 and
friends and we do not backtrack immediately over the goal. As a result,
changes to backtrackable global state are retained. This is similar that
using set_prolog_flag(toplevel_mode, recursive)
.Name = Var
terms, providing access to the actual variable
names.Any remaining options are passed to pengine_send/3.
Note that the predicate pengine_ask/3 is deterministic, even for queries that have more than one solution. Also, the variables in Query will not be bound. Instead, results will be returned in the form of event terms.
true
or false
, indicating whether we
can expect the pengine to be able to return more solutions or not, would
we call
pengine_next/2.Defined in terms of pengine_send/3, like so:
pengine_ask(ID, Query, Options) :- partition(pengine_ask_option, Options, AskOptions, SendOptions), pengine_send(ID, ask(Query, AskOptions), SendOptions).
chunk(false)
.Remaining options are passed to pengine_send/3. The result of re-executing the current goal is returned to the caller's message queue in the form of event terms.
Defined in terms of pengine_send/3, as follows:
pengine_next(ID, Options) :- pengine_send(ID, next, Options).
Defined in terms of pengine_send/3, like so:
pengine_stop(ID, Options) :- pengine_send(ID, stop, Options).
force(true)
,
the pengine is killed using abort/0 and pengine_destroy/2
succeeds.pengine_sandbox
. The example below creates a new
application
address_book
and imports the API defined in the module file
adress_book_api.pl
into the application.
:- pengine_application(address_book). :- use_module(address_book:adress_book_api).
alias
option when creating the pengine.true
if the pengines is destroyed
automatically after completing the query.debug_info
is present.console.log(Message)
if there is a console. The predicate
pengine_rpc/3 calls debug(pengine(debug), '~w', [Message])
.
The debug topic pengine(debug)
is enabled by default.
at_exit
option. Destroys child
pengines using pengine_destroy/1.
Cleaning up the Pengine is synchronised by the pengine_done
mutex. See read_event/6.
src_text
and
src_url
optionsModule | is a new temporary module (see in_temporary_module/3) that may be (further) prepared by this hook. |
Application | (also a module) associated to the pengine. |
Options | is passed from the environment and should (currently) be ignored. |
Options | provides the options as given to ask |
Defined in terms of pengine_send/3, as follows:
pengine_respond(Pengine, Input, Options) :- pengine_send(Pengine, input(Input), Options).
ignore(call(Closure, E))
.
A closure thus acts as a handler for the event. Some events are
also treated specially:
Valid options are:
all
,
all_but_sender
or a Prolog list of NameOrIDs. [not yet
implemented]copy_term_nat(Query, Copy), % attributes are not copied to the server call(Copy), % executed on server at URL Query = Copy.
Valid options are:
pengines:time_limit
.Remaining options (except the server option) are passed to pengine_create/1.
'$BLOB'(Type)
. Future
versions may include more info, depending on Type.prolog
and various JSON dialects. The hook
event_to_json/3 can be used
to refine the JSON dialects. This hook must be used if a completely
different output format is desired.pengines_io.pl
.success(ID, Bindings, Projection, Time, More)
and output(ID, Term)
into a format suitable for processing
at the client side.
throw(http_reply(authorise(basic(Realm))))
Start a
normal HTTP login challenge (reply 401)throw(http_reply(forbidden(Path)))
) Reject the request
using a 403 repply.Valid options are:
timeout
.