create/2
create(+Descriptor,-Obj)
term
object
Obj is a newly created and initialized object. Descriptor is a term describing the object to create. After memory is allocated and any slot initializations are performed, a create message is sent to the object.
The functor of Descriptor indicates the class to create. The arguments of the create message are the arguments of Descriptor.
instantiation_error
Descriptor is unbound.
domain_error
Descriptor is not a valid create
descriptor.
resource_error
unable to allocate enough memory for object.
You must have a create/N
method for every
arity N you want to be able to use in creating instances of a
class. This includes arity 0. If no such method exists, then a domain
error will be raised.
Given the class definition
:- class point = [public x:integer=1, public y:integer=2]. Self <- create. Self <- create(X, Y) :- Self << x(X), Self << y(Y). :- end_class point.
the command
| ?- create(point, Point1).
creates a point
object, with the default slot values for x
and y
, and
binds variable Point1
to the new object. The command
| ?- create(point(10,15), Point2).
creates a point
object with values 10 and 15 for slots x
and y
,
respectively, and binds variable Point2
to the new object.
destroy/1