Some methods are defined by method clauses, between the
class/1
directive and the end of the class's definition. Others
are generated automatically. There are three kinds of messages in
Quintus Objects, distinguished by the message operator they occur
with:
>>
<<
<-
Quintus Objects automatically generates some get and put methods. And, it expects particular message names with the send operator for create and destroy methods. For the most part, however, you are free to use any message operators and any message names that seem appropriate.
A method clause has one of these message operators as the principal
functor of its head. Its first argument, written to the left of the
message operator, is a variable. By convention, we use the variable
Self
. Its second argument, written to the right of the message
operator, is a term whose functor is the name of the message and whose
arguments are its arguments.
For example, in the class whose definition begins as follows, a
0-argument send message named increment
is defined. No parentheses are
needed in the clause head, because the precedence of the <-
message
operator is lower than that of the :-
operator.
:- class counter = [public count:integer = 0]. Self <- increment :- Self >> count (X0), X1 is X0 + 1, Self << count (X1).
Its definition uses the automatically generated get and put methods
for the public slot count
.
It may look as though this technique is directly adding clauses to the
>>/2
, <</2
and <-/2
predicates, but the method clauses are
transformed by term expansion, at compile time. However, the method
clauses have the effect of extending the definitions of those
predicates.
Methods are defined by Prolog clauses, so it is possible for them to fail, like Prolog predicates, and it is possible for them to be nondeterminate, producing multiple answers, upon backtracking. The rest of this section describes different kinds of methods.