| Did you know ... | Search Documentation: |
| Calling Prolog |
Object to represent Prolog
PCE can invoke Prolog predicates via the predefined object @prolog
by sending a message there. When a message is sent to @prolog,
the selector of the message will be used as predicate name and the
arguments will be transformed in reference mode (see T Object -> Term)
to Prolog terms and then passed as arguments to the predicate.
Normally, the message to Prolog will be activated through a message object associated with a UI object (similar to call-back in many C-based window packages). Examples:
1 ?- new(B, button(ok, message(@prolog, do_xyz))). 2 ?- new(T, text_item(file, '', message(@prolog, consult, @arg1))).
The first example invokes the predicate do_xyz/0 when the user presses the button. The second invokes consult/1 when the user hits RETURN with the typed value as argument.
The examples above illustrate how PCE can invoke predicates in Prolog. Sending the PCE message succeeds or fails, depending on success or failure of the Prolog predicate invoked. PCE may also obtain information from Prolog by invoking a get method on @prolog. The return value is passed through the last argument. Normally, Prolog is called like this through an obtainer used to implement a get-method of a Prolog-defined class. Example:
area2(Gr, Area) :-
get(Gr, width, W),
get(Gr, height, H),
Area is W * H.
?(@prolog, area2, Gr)
In this example the obtainer evaluates to the area of the graphical.
Parent: Prolog Interface