Author(s): Angel Fernandez Pineda.
Version: 1.3#124 (1999/11/27, 4:4:5 MET)
Version of last change: 1.3#78 (1999/10/13, 18:31:8 MEST)
This package is required to enable user code to create objects and manipulate them, as well as loading any needed class.
objects
):- module(ModuleName,Exports,[objects]).You can use objects even if your code is a class. Note that declaring a class does not automatically enables the code to create instances.
:- class(ModuleName,[],[objects]).This package enables both static and dynamic usage of objects.
use_class/1
,
instance_of/2
,
new/2
.
objects
)It establishes an usage relationship between the given file (which is supposed to declare a class) and current source. Usage relationships are needed in order to enable code to create instances of the given class, and to make calls to instances derived from such class.
Since an interface is some kind of class, they may be used within this declaration but only for semantic checking porpouses. Instances will not be derived from interfaces.
use_class/1 is used in the same way as
use_module/1
.
Usage: :- use_class(ClassSource)
.
ClassSource
.
ClassSource
is path to a file declaring a class.
(user(... /objects_doc):class_source/1
)
Statically declares an identifier to be an instance of a given class.
It may be used as
new/2
predicate except for:
For every statically declared object the given constructor will be called at program startup. Those instances may be destroyed manually, but it is not recommended.
When reloading the involved class from the CIAO toplevel shell. It may destroy statically declared instances, and create them again.
Statically declared instances must be called using a specifically designed module-qualification: ClassName(Object):Goal
. For example:
:- module(example,[main/0],[objects]). :- use_class(library(counter)). :- cnt instance_of counter(10). main :- counter(cnt):decrease(1), counter(cnt):current_value(X), display(X).
But statically written code (only) is allowed to use module-style qualifications as a macro:
main :- cnt:decrease(1), cnt:current_value(X), display(X).
Notice that dynamically expanded goals such as X=cnt,X:decrease(1)
will not work, use X=counter(cnt),X:decrease(1)
instead.
Usage: :- instance_of(Object,Constructor)
.
Object
to be an instance of the class denoted by Constructor
.
Object
is an unique atom which identifies an object.
(user(... /objects_doc):instance_id/1
)
Constructor
is a term whose functor matches a class name.
(user(... /objects_doc):constructor/1
)
This declaration has the same effect as
instance_of/2
.
Usage: :- new(Object,Constructor)
.
objects
)
Usage: class_source(Source)
Source
is path to a file declaring a class.
Usage: constructor(Cons)
Cons
is a term whose functor matches a class name.
Usage: instance_id(ID)
ID
is an unique atom which identifies an object.
Usage: class_name(ClassName)
ClassName
is an atom denoting a class.
It establishes an usage relationship between the given file (which is supposed to declare a class) and current source. Usage relationships are needed in order to enable code to create instances of the given class, and to make calls to instances derived from such class.
Since an interface is some kind of class, they may be used within this declaration but only for semantic checking porpouses. Instances will not be derived from interfaces.
Statically declares an identifier to be an instance of a given class.
It may be used as
new/2
predicate except for:
For every statically declared object the given constructor will be called at program startup. Those instances may be destroyed manually, but it is not recommended.
When reloading the involved class from the CIAO toplevel shell. It may destroy statically declared instances, and create them again.
Statically declared instances must be called using a specifically designed module-qualification: ClassName(Object):Goal
. For example:
:- module(example,[main/0],[objects]). :- use_class(library(counter)). :- cnt instance_of counter(10). main :- counter(cnt):decrease(1), counter(cnt):current_value(X), display(X).
But statically written code (only) is allowed to use module-style qualifications as a macro:
main :- cnt:decrease(1), cnt:current_value(X), display(X).
Notice that dynamically expanded goals such as X=cnt,X:decrease(1)
will not work, use X=counter(cnt),X:decrease(1)
instead.
Go to the first, previous, next, last section, table of contents.