Logtalk reference manual
Built-in method: clause/2

clause/2

Description

clause(Head, Body)

Enumerates, by backtracking, the clauses of a dynamic predicate. When the predicate indicator for Head is declared in a uses/2 or use_module/2 directive, the predicate enumerates the clauses in the referenced object or module. Otherwise it enumerates the clauses for an object's dynamic predicate.

This method may be used to enumerate clauses for predicates that are not declared dynamic for dynamic objects provided that the predicates are declared in this.

Template and modes

clause(+callable, ?body)

Errors

Head is a variable:
instantiation_error
Head is a neither a variable nor a callable term:
type_error(callable, Head)
Body is a neither a variable nor a callable term:
type_error(callable, Body)
The predicate indicator of Head, Name/Arity, is that of a private predicate:
permission_error(access, private_predicate, Name/Arity)
The predicate indicator of Head, Name/Arity, is that of a protected predicate:
permission_error(access, protected_predicate, Name/Arity)
The predicate indicator of Head, Name/Arity, is that of a static predicate:
permission_error(access, static_predicate, Name/Arity)
Head is not a declared predicate:
existence_error(predicate_declaration, Name/Arity)

Examples

To retrieve a matching clause of a local dynamic predicate or a dynamic predicate in this:
clause(Head, Body)
To retrieve a matching clause of a public or protected dynamic predicate in self:
::clause(Head, Body)
To retrieve a matching clause of a public dynamic predicate in an explicit object:
Object::clause(Head, Body)

See also

abolish/1, asserta/1, assertz/1, retract/1, retractall/1
dynamic/0, dynamic/1
uses/2, use_module/2