An object object-identifier is declared by writing it in the following form:
object-identifier :: { sentence-1 & sentence-2 & : sentence-n }.
where object-identifier is a Prolog term that is either an atom or a compound term of the form functor(V1,...,Vn), where V1,...,Vn are distinct variables. The object body consists of a number of sentences, possibly none, surrounded by braces, where each sentence is either a method-directive, to be executed when the object is created, or a method-clause. A method is a number of method-clauses with the same principal functor. A method-clause has a clausal syntax similar to that of Prolog, but instead of usual predicate calls in the body of a clause there are method-calls. Ordinary Prolog goals are also allowed in a prefixed form, using `:' as a prefix. A method-directive is a directive that contains method-calls.
All sentences are subject to term expansion
(see Term and Goal Expansion, built-in predicate expand_term/2
) before
further processing, so in particular definite clause grammar
syntax can be used in method-clauses. In addition, before
expand_term/2
, sentences are expanded by the
predicate user:method_expansion/3
.
method_expansion(
+Term1,
+ObjectIdentifier,
?Term2)
hookuser:method_expansion(
+Term1,
+ObjectIdentifier,
?Term2)
user:term_expansion/[2,4]
. At the end of an object
definition, user:method_expansion/3
is called with
end_of_object
.