The Prolog interface is based on the idea of a Prolog server that provides its service by answering queries from external applications (typically Java applications). The Prolog interface in PrologBeans is defined in library(prologbeans), which implements the Prolog server and exports the following predicates:
start
start(
+Options)
start/[0,1]
will not return until a server shutdown
occurs. Options should be a list of zero or more of:
port(
?Val)
get_server_property/1
, typically from a
server_started
event listener.
accepted_hosts(
+Val)
['127.0.0.1']
).
session_timeout(
+Val)
0
).
session_gc_timeout(
+Val)
0
).
For example:
:- start([port(7500), accepted_hosts(['127.0.0.1','99.8.7.6'])]).
shutdown
shutdown(+Mode)
now
no_sessions
no_connections
register_query(
+Query,
:PredicateToCall)
register_query(
+Query,
:PredicateToCall,
+SessionVar)
unregister_query(
Query)
). The
goal PredicateToCall will be called when a query matching
Query is received.
Typically, Query and PredicateToCall share variables that
are instantiated by the call, and the instantiated Query
is passed back to the client. In general, variable bindings can be
arbitrary Prolog terms, including terms containing unbound variables.
However, any unbound variables with attributes or blocked goals
attached to them will be replaced by plain, brand new variables. This
is analogous to the way attributed variables are handled in terms that are
written, copied, asserted, gathered as solutions to findall/3
and friends, or raised as exceptions. If the attributes must be passed
to the client, the Prolog code can obtain them by using
copy_term/3
(see ref-lte-cpt).
The goal is called determinately, i.e. it is never backtracked into.
If it fails, the term no
is passed to the client instead of the
instantiated Query. If it raises an exception E,
the term error(
E)
is passed to the client instead of the
instantiated Query.
Before calling the query, the variable SessionVar, if
given, is bound to the id of the current session. Session ids are
typically generated in web applications that track users and mark all
consecutive web-accesses with the same session id.
unregister_query(
+Query)
session_get(
+SessionID,
+ParameterName,
+DefaultValue,
-Value)
session_put(
+SessionID,
+ParameterName,
+Value)
session_put/3
will not be undone when backtracking (the current
implementation is based on assert
). Arguments:
register_event_listener(
+Event,
:PredicateToCall)
register_event_listener(
+Event,
:PredicateToCall,
-Id)
once(
PredicateToCall)
) when the event matching Event occurs
(event matching is on principal functor only). If the goal fails or
raises an exception a warning is written to user_error
but the failure
or exception is otherwise ignored. Arguments:
unregister_event_listener/1
to remove this event listener.
The predefined events are as follows:
session_started(
+SessionID)
session_ended(
+SessionID)
server_started
server_shutdown
Attempt to register an event listener for other events than the predefined events will throw an exception.
More than one listeners can be defined for the same event. They will be
called in some unspecified order when the event occurs.
unregister_event_listener(
+Id)
Unregister a previously registered event listener. The Id is the
value returned by the corresponding call to
register_event_listener/3
. It is an error to attempt to
unregister an event listener more than once.