1.110 class object

Class object is the root of the class hierarchy. It defines common behaviour, mainly to do with object management:

Creating objectsobject->initialise
Destroying objectsobject->free, object->done
Cloning objectsobject<-clone
Saving objects on fileobject->save_in_file
Adding attributesobject->attribute
Programmingobject->send_method, object->get_method

Any class in PCE must be a sub-class of class object and therefore any object listens to the methods defined on this class.

It is allowed to create instances of class object and extend the instance using object-level programming to realise a single object meeting some specification. See:

object->attribute Define object-level attributes
object->send_method Add object-level send method
object->get_method Add object-level get method
See also
- class interceptor
- topic Object-level Programming

1.110.1 Send methods

object ->_check: recursive=[bool]
Validate the type of the instance variables. If the argument is @on or @default, validation continues recursively over instance variables that contain objects. This method is protected against loops in the data-structures.

Normally invoked through the Prolog predicate checkpce/0.

Diagnostics: See related error objects

See also
- !freed_value_value
- !freed_key_value
- !freed_element_value
- !freed_cell_value
- !freed_slot_value
- !bad_slot_value
- !creating
- !no_variable
- !checked_objects
- object->for_slot_reference
- class type
object ->_free:
Inherits description from: object<-_class
See also
- class ?
- object->free
object ->_inspect: bool
Inherits description from: object<-_class
See also
class ?
object ->_instance_of: class
Inherits description from: object<-_class
object ->delete_hyper: hyper
Detach a hyper from an object.
object ->attach_hyper: hyper, object
Called from class hyper as part of hyper->initialise and hyper->unlink. These methods should never be called directly by the user. It is however possible to redefine these methods to intercept the creation and destruction of hyper-links. A redefinition should always call this method.
See also
object->delete_hypers.
object ->attribute: attribute|name, value=[any]
Attach an instance variable to an object rather than to a class. If an attribute with this name is already present, the value of the original attribute is replaced.

An error is raised if the class already defines an instance variable with the same name.

See also
- graphical->popup
- class sheet
- object<-all_attributes
- attribute<-convert
- class attribute
- object-interceptor
object ->convert_loaded_object: old_version=int, current_version=int
Called by source_sink<-object if the current save version is not the same as save version when the file was loaded. The two arguments are the old and the new save versions. See pce<-save_version.
See also
object->initialise_new_slot
object ->delete_attribute: name|attribute
Delete (named) attribute that has previously be attached using object->attribute. Fails silently if the attribute is not present.

Diagnostics: Fails (silently) if the attribute is not defined.

See also
object->attribute
object ->delete_hypers: name=[name], condition=[code]
Delete all hypers matching the name and condition. See object<-find_hyper for the interpretation of the name and condition arguments.
object ->done:
This method is used to help the PCE garbage collector and should normally be invoked after the program is done with the answer of a get operation and wants to be sure that the returned object is deleted when no longer referenced:
.....
get(Area, size, Size),
....
send(Size, done).

The receiving object will be deleted from the object base as with object->free if the receiver has no object<-references, object<-lock_object is @off and object<-protect is @off.

In the example above object->done is equivalent to object->free as the size object returned by area<-size is created by this method (provided the .... computation does not lock, protect or make the size an attribute of some other object. In the example below, using object->free will corrupt PCE's database:

....
get(Graphical, area, Area),
....
free(Area).		% ==> ERROR!!!

The area object will be deleted and the slot graphical<-area will be pointing in the dark (checkpce/0 will find such problems).

Using object->done is often not necessary. After a user-event has been processed all unreferenced and unlocked objects will be deleted from the object base automatically. Unreferenced objects created during the execution of a user-defined method for a PCE class are also deleted automatically. object->done is useful when a lot of garbage objects are created in a loop.

See also
object<-lock_object
object ->equal: to=any
Succeeds if the argument has the same reference. Note that this method is redefined by various classes. Equality may also be tested using class ==. See also object->same_reference.

Bugs: The notion of equality is not very clear in PCE.

See also
- class \==
- class ==
object ->error: error=error, context=unchecked ...
Raise an error (exception) on this object. Error (normally specified by its error<-id and converted by error<-convert) is the error to be raised. The remaining context arguments provide context information about this error. Performs the following steps:

object ->for_slot_reference: action=code, recursive=[bool]
This method is intended to help writing analysis programs for the database. It scans all slot-references of the receiving object. When the argument is @on or @default, it will continue recursively over the slot-fillers.

For each slot-reference, code is executed with the following bindings:

@arg1 The instance
@arg2 Type of slot reference
@arg3 The slot
@arg4 The value of the slot

The Type of slot reference is one of:

slot
For normal objects. @arg3 is bound to the name of this variable
cell
For chains. @arg3 is bound to the 1-based index of the cell
element
For vectors. @arg3 is bound to the index
key
For hash_tables. @arg3 is bound to the key; @arg4 to the related value.
See also
object->_check
object ->free:
Remove an object from the PCE object base. This behaviour is the normal way to get rid of existing objects. object->free performs the following steps:

object ->get_method: get_method|chain
Add a get-method to this individual object. Object-level defined get-methods overrule Class-defined get-methods. An object level method may refer to its corresponding class level method using object->get_class.
See also
- object<-get_class
- class method_group
- class method
- object<-slot
- object<-all_get_methods
- object->send_method
- class->get_method
- object-interceptor
object ->has_get_method: selector=name
Test if object defines get_method.
object ->has_send_method: selector=name
Test whether object implements the specified send/get behaviour. This test is equivalent to testing whether {object<-get_method, object<-send_method} returns a value but avoids the creation of a tuple. See also class<-send_method and class<-get_method.
object ->is_off: name
Test if Obj object<-name returns @off.
object ->is_on: name
Test if Obj object<-name returns @on.
object ->not_has_value: name, any
Test if Obj object<-name not-equal 2nd argument.
object ->has_value: name, any
Execute the get operation object<-Name and compare the result to the argument. Succeed if they are equal (have same reference), fail otherwise.

This method is intended to test on attribute values. Similar and more powerful results can be obtained using class ==.. It's usage is to be preferred. The following code objects and Prolog fragments all test whether the point<-x of the point object @p equals 3:

Prolog:

get(@p, x, 3)              % Uses Prolog unification
send(@p, has_value, x, 3)

Code fragments:

message(@p, has_value, x, 3)
@p?x == 3

object->not_has_value is equivalent to object->has_value, but returns the inverse result. object->is_on is equivalent to object->has_value: @on and object->is_off is equivalent to object->has_value: @off.

See also
- object->is_on
- object->is_off
- class \==
- object->not_has_value
- class ==
object ->initialise:
No-operation (just succeeds). Implemented to allow any class perform a
send_super(Self, initialise).

Any class should have a method object->initialise. This method is invoked from PCE's virtual machine to initialise an object from the parameters given to the object creation operation (new/2. class create, class<-instance.

The creation of objects is discussed in detail with class<-instance.

See also
- class<-instance
- topic Creating Objects
object ->initialise_new_slot: new=variable
Part of saved-object conversion (see source_sink<-object). Called when -while loading an instance from a file-, the current definition of the class has a new instance variable (compared to when the instance was saved to file using object->save_in_file). The argument is the new variable object from the class. May be used to initialise the new slot to some sensible value.
See also
object->convert_loaded_object
object ->inspect: bool
If @on and the class of the object has one of the change trapping messages attached to it, changes to the object are forwarded (to the application) via these change messages. If @off, these messages have no effect.
See also
- class-changed_messages
- object<-inspect
- topic Changes
- class->freed_message
- class->created_message
- class->changed_message
object ->instance_of: class
Succeeds if the object is an instance of the argument class or one of its subclasses. Note that class<-convert converts class-names to class objects:
send(Obj, instance_of, graphical)

is the advised way to verify that Obj is a graphical.

The method pce<-convert may be used to combine testing with possible type conversion. See also type->validate and type<-check. If one wants to test whether an object is a graphical object, a node object or @nil, the following two test are equivalent:

(   send(Obj, instance_of, graphical)
;   send(Obj, instance_of, node)
;   Obj == @nil
)

or

send(type('graphical|node*'), validate, Obj)
See also
pce<-convert
object ->lock_object: bool
Inherits description from: object<-lock_object
See also
- object<-lock_object
- object<-_flags
- object->protect
object ->name_reference: name*
Give/change the global named reference associated with the object. See also object<-object_reference.

Diagnostics:

object ->protect:
Protect an object against destruction with object->free or one of the other objects destruction methods. The global PCE objects @pce, @prolog, etc. are protected this way.

There is no way to unprotect protected objects or to destroy them.

See also
- visual->destroy
- object<-protect
- object<-_flags
- topic Removing Objects
- object->lock_object
- object->free
- object->destroy
object ->report: kind={status,inform,progress,done,warning,error,fatal}, format=[char_array], argument=any ...
Report a message related to the specified object. This method locates the visual object from which the user invoked the current command using constant<-receiver and invokes visual->report on this object.

If @event is unbound the error is caused by a query from the host-language interaction window and PCE thus prints the message using pce->format.

Some classes redefine this method because they know they are related to some visual object. See also object<-report_to.

See also
visual->report
object ->same_class: object
Test if two objects belong to the same class. The following two executable objects are the same:
Obj1?class == Obj2?class.

and

message(Obj1, same_class, Obj2)
See also
- object<-class
- class->is_a
object ->same_reference: to=any
Test if i'm the same object as the argument. This method verifies both objects have the same identity. The method object->equal performs the same test, but is refined by various classes to test for same properties. See -for example- point->equal.
object ->save_in_file: file
Save an object and all objects that can be reached from it to a file. This method takes care of cyclic structures. The save-format is binary. The object may be reloaded in this or in another PCE process using source_sink<-object. When the object is reloaded in this PCE process, the combined functionality is similar to object<-clone.

When the data, manipulated by the application is stored in PCE, the normal way is to attach all this information to a single object (normally a hash_table, sheet or chain) and save this object to a file. All attached objects (i.e. all data needed by the application to save its persistent data) are then saved in the file.

PCE's save and load functionality has a limited way to deal with versions. The conversion activities are described with source_sink<-object.

Diagnostics:

object ->send_class: selector=name, argument=unchecked ...
Invoke send behaviour of the class, bypassing object-level send_method objects attached to this object. See object<-get_class for details..
See also
object->send_method
object ->send_hyper: hyper_name=[name], selector=name, argument=unchecked ...
Perform a broadcast send-operation to all (named) object<-hypered objects. Similar to object<-get_hyper, but does not stop if the method is received successfully. Succeeds if there was at least one hypered object accepting the message, fails otherwise.
object ->send_method: send_method|chain
Add a send-method to this individual object. Object-level defined send-methods overrule Class-defined send-methods. An object level method may refer to its corresponding class level method using object->send_class.
See also
- object->send_class
- class method_group
- class method
- object<-all_send_methods
- object->slot
- class->send_method
- object->get_method
- object-interceptor
object ->send_sub: selector=name, argument=unchecked ...
Send to @receiver, using behaviour at the level of the class @receiver is an instance of. See also object<-get_sub.
object ->send_super: selector=name, argument=unchecked ...
Invoke behaviour of the super-class. This behaviour is intended to be used only for using behaviour of the super-class when defining new classes.
See also
- object<-get_super
- topic Methods
- topic Class-level Programming
object ->send_super_vector: unchecked ...
Combines object->send_super and object->send_vector, creating an argument vector from the leading arguments and vector and invoking behaviour defined at the super-class. See object->send_super and object->send_vector for details.
See also
- object->send_super
- object->send_vector
object ->send_vector: unchecked ...
object->send_vector supports the implementation of methods with variable argument list. Its format is:
unchecked..., Vector, [shift]

First, a list is created containing the following arguments:

object ->slot: name|int, unchecked
Set the value of a (class-defined) slot without activating the corresponding method.

The slot specification (first argument) is either the slot-name, or the offset in the object (1-based). The latter possibility is for very specific (internal) use.

This method should only be used from a send-method that has the same name (selector) as the slot and serves as a wrapper around the slot to deal with side-effects:

:- pce_begin_class(person, object).

variable(date_of_birth,	date, get, "When person was born").
...

date_of_birth(Person, Date:date) :->
        (   send(Date, after, new(date))
        ->  send(Person, report, error,
                     'Cannot be born in the future!'),
                fail
        ;   send(Person, slot, date_of_birth, Date)
        ).

Bugs: This message should also apply to object-level defined attributes (see object->attribute.

See also
- class variable
- object<-slot
- class->send_method
- object->send_method
object ->unlink:
The method object->unlink is called by object->free. Its task is to unlink the instance from its environment. The object->unlink method may not be called directly by the user. The user should provide an unlink method when writing a user-defined class that requires specialised unlink behaviour.

Some examples:

object ->unlinking:
Succeeds if the object is in currently being object->unlink’ed. Intended as a test in object->unlink methods to avoid unnecessary computation.

1.110.2 Get methods

object <-_arg: int -> unchecked
The nth argument (1-based) of the term description. Unless overruled at the object level, this is equivalent to:
get(Obj, ?(Obj?class?term_names, element, N), Arg).

This behaviour is intended to remain reserved for system usage. Do not rely on its definition.

See also
- chain<-_arg
- object<-functor
- object<-_arity
- class-term_names
- class ?
- topic Object -> Term
object <-_arity: -> int
Number or arguments to the term description. Unless overruled, this is the size of the term_names vector of the associated class.
See also
- chain<-_arity
- object<-functor
- object<-_arg
- class ?
- topic Object -> Term
object <-_class_name: -> name
object <-_flags: -> name
object <-_inspect: -> bool
object <-_man_id: -> name
object <-_references: -> int
object <-_slot: name|int -> unchecked
object <-_class: -> class
These methods starting with an’_’(underscore) are defined both on class function and class object. Their behaviour is equivalent to the counterpart with the leading underscore deleted for normal objects. As these methods are explicitly defined on class function however, invoking one of these methods to a function will cause the function itself to handle the message instead of the evaluation. Example:
?- new(O, @display?size),
   get(O, '_class_name', C1),
   get(O, class_name, C2).

C1 = ?
C2 = size

Bugs: It is probably more elegant to introduce a separate send- and get- operation that does not evaluate the receiver.

See also
- object<-class
- class ?
object <-all_constraints: create=[bool] -> chain
object <-all_get_methods: create=[bool] -> chain
object <-all_hypers: create=[bool] -> chain
object <-all_send_methods: create=[bool] -> chain
object <-all_attributes: create=[bool] -> chain
Return a chain holding all the object-level extensions to the object of the given type. If create equals @on, this call will always succeed, possibly returning an empty chain. Otherwise the call might fail.

The following extensions are defined:

object->attribute Object-level instance variable
constraint Binary constraint between two objects
hyper Binary relation (two-way attribute)
object->recogniser Handler for event objects (class graphical)
object->send_method Object-level method (send)
object->get_method Object-level method (get)

See also class constraint and class hyper.

See also
- object->attribute
- object-interceptor
object <-attribute: name -> unchecked
Get the value of an attribute associated to the object using object->attribute. The attribute may also me requested using a plain get operation:
?- new(@o, object),
   send(@o, attribute, gnus, 4).

?- get(@o, attribute, gnus, G).
?- get(@o, gnus, G).

The two are equivalent, except that the latter gives an error if no such attribute is defined.

object <-class: -> class
Instance of class class to which this object belongs. The normal way to test that an object is of some particular class is either object->instance_of or object<-class_name. In most situations the first is to be preferred.
See also
- object<-class_name
- object<-_class
- object->same_class
object <-class_name: -> name
Name of the class the object belongs to. Shorthand for:
get(Object?class, name, ClassName).
See also
- object<-class
- object<-_class_name
object <-class_variable_value: name -> any
Get value of associated class_variable object. See also class_variable/4. Note that, in the absence of a method or variable with the name name, object<-Name is equivalent.
object <-clone: -> object
Object object<-clone creates a clone of an object. The semantics of cloning objects in general are difficult to define. Which related objects are to be cloned and which are to be shared between the clone and the original object?

The approach taken by PCE is not particularly neat. We do not recommend heavy use of this facility.

Object are cloned recursively. This implies all objects that can be reached from this object are cloned as well. The algorithm deals correctly with cyclic structures.

While executing a recursive clone, two flags may influence the result:

variable<-clone_style Defines the type of relation
class<-clone_style Defines the type of object

Please consult the documentation of these for details.

Bugs: The semantics are ill defined. Be very carefull with plain cloning and study this description carefully before going ahead. When in doubt, use the inspector tool from the main menu to find out about the result.

See also
- class-clone_style
- object->save_in_file
object <-convert: int|char_array -> object
The method object<-convert is called by type<-translate, part of the generic type-checking and type conversion system. It is not a normal method not the receiver, but the result is an instance of the class on which the method is defined. The receiver is normally the class.

The task of the object<-convert method is to translate the argument into an instance of the requested type.

For class object itself no translation is necessary as anything in PCE already is an instance of class object. This method will therefore never be called directly by the PCE type conversion system. This method translates a text (char_array object) of the form @<name> into an object if <name> is a valid object reference. This method is useful for defining other conversion functions.

object <-create_context: condition=[code] -> object
If the receiver is executing object->initialise, scan the goal stack searching for a receiver higher in the goal stack for which condition succeeds. Condition is executed with the following arguments:
@receiver receiving object
@arg1 receiver of message of parent goal
@arg2 implementation of message of parent goal

This method is intended to find the context in which an object (often a graphical) is created, allowing it to query the context for additional information. See also visual<-contained_in.

object <-find_all_send_methods: condition=[code] -> chain
Compute a chain with all behaviour objects that may be used to invoke send behaviour on this object. It will analyse:

object <-find_hyper: hyper_name=[name], test=[code] -> hyper
Find hyper-object from specifications. hyper_name is the name of the hyper, seen from the receiver of this message. If hyper_name is @default, all hypers are considered. test is a code object. If it is not @default, it is executed using the following arguments:
@arg1 Receiver of this message
@arg2 Hyper object
@arg3 Object at other end of the hyper.

See also object<-hypered.

object <-functor: -> name
Functor of the term description of the object. Unless overruled, this is equivalent to object<-class_name.
See also
- topic Object -> Term
- class-term_functor
- object<-_arity
- object<-_arg
object <-get_class: selector=name, argument=unchecked ... -> unchecked
Invoke get_method on object, bypassing possible object-level get_methods associated with object->get_method. This method serves a similar purpose as object->get_super when using class-level programming.
See also
object->get_method
object <-get_hyper: hyper_name=[name], selector=name, argument=unchecked ... -> unchecked
Perform a broadcast get operation on objects object<-hypered to this object. If a hyper_name is given only hypers with this name are considered. Otherwise all hypers are considered. As soon as one of the hypered objects returns a value, this method returns with this value. Otherwise the method fails. Example:
?- new(@o, object),
   new(_, hyper(@o, bitmap('pce.bm'), bitmap)),
   new(_, hyper(@o, text(hello), text)).

?- pce_catch_error(no_behaviour,
                                   get(@o, get_hyper,
                                           @default, string, S).
S = hello

?- pce_catch_error(no_behaviour,
                                   get(@o, get_hyper,
                                           @default, pixel, 3, 5, P).
P = @off

The first query is answered by the text object, while the latter is answered by the bitmap object (delegated to the bitmap<-image). Note the use of pce_catch_error/2 to avoid an error while broadcasting to objects that do not understand the method.

object <-send_method: name -> tuple
object <-get_method: name -> tuple
This method locates the implementation for the specified selector for the specified (send/get) type of operation. It will try (in this order):

object <-get_sub: selector=name, argument=unchecked ... -> unchecked
Invoke message on @receiver, using the definition from the object's own class instead of the current class. See class->get_method for further details.

Bugs: Actually, a normal get operation executed in a method already performs a object<-get_sub. Reserved fro future extension.

object <-get_super: selector=name, argument=unchecked ... -> unchecked
Invoke behaviour of the super-class. This behaviour is intended to be used only for using behaviour of the superclass when defining new classes. This method is only valid in the context of class-defined methods. The receiver should be the same object as the receiver of the executing method (i.e. object<-get_super is always to it self).

See also object<-slot.

See also
- topic Methods
- topic Class-level Programming
- object->send_super
object <-get_vector: unchecked ... -> unchecked
Invokes a get-method on the object itself. The first element of the vector is used as a selector, the subsequent ones are used as arguments to the behaviour. E.g.
get(@prolog, get_vector, vector(plus, 1, 1), X).

Is a very complicated way to add 1 and 1.

This behaviour is intended to deal with delegating messages trapped via the object->get_catch_all behaviour.

See also
object->send_vector
object <-hypered: hyper_name=[name], test=[code] -> object
Find a hyper-related object. Name is the name of the hyper (seen from the side of the receiver). Test is an optionally additional test. If present, this test is executed using the following arguments:
@arg1 This object
@arg2 The hyper object
@arg3 The object at the other end of the hyper

The first matching object is returned. See also object<-all_hypers.

object <-inspect: -> bool
Inherits description from: object->inspect
See also
- object->inspect
- object<-_inspect
object <-lock_object: -> bool
When @on, PCE's garbage collector will not remove this object, even if it has no references. Globally named objects are by default locked, as are most reusable objects for which the class maintains a table: types, names, modifiers, etc.

A locked object is destroyed by object->free. To protect an object against object->free, use object->protect.

When @off, the lock is removed from the object. If the object has no references, it will be object->free’d. If this is not desirable, use object<-unlock.

See also
- object->protect
- object->done
- object->lock_object
object <-object_reference: -> name|int
Reference name of the object (see object->name_reference) or integer reference for objects that have no named reference. See also pce<-object_from_reference.
See also
pce<-object_from_reference
object <-print_name: -> text=char_array
The method object<-print_name is intended to convert an object into a textual representation. It serves two purposes:

object <-protect: -> bool
Inherits description from: object->protect
See also
object->protect
object <-references: -> int
PCE uses reference counts for the incremental garbage collector. The number of references is the number of slot relations towards this object.

Note that PCE does not know which objects have references to an object; slot-relations are uni-directional.

See also
- tool Inspector
- topic Garbage collection
- object<-_references
object <-report_to: -> object
Object for object->report. The default for non-visual objects is the receiver of the current event (@event). See also visual<-report_to.
object <-self: -> object
Returns the object itself. Hardly ever necessary within the architecture of PCE.
object <-slot: name|int -> unchecked
Get the value of the named slot, bypassing protection. When given an integer, get the value of the nth-slot (counting from 1).

This method is used in the implementation of get_method objects if the get method wants to access a slot with the same name without interaction from the method. See also class->get_method.

See also
- class variable
- class->get_method
- object->get_method
- object->slot
- object<-_slot
object <-storage_reference: -> any
This method is used by object->save_in_file to handle shared object resources (colours, fonts, etc.). If this method is executed successfully, object->save_in_file stores the classname of the the object and the returned object.

source_sink<-object loads the classname, converts the classname to a type object, loads the returned reference object and attempts type<-check to produce an object of the requested type.

See colour<-storage_reference for an example.

object <-unlock: -> unchecked
Unlock object and return object<-self. If, after unlocking, the object has no references, it will be pushed on the‘anser stack’, making it visible to the incremental garbage collector.

In combination with object->lock_object, this method may be used to disconnect an object from its environment, handing it back to the incremental garbage collector. An example can be found in emacs_window<-prompt, a part of PceEmacs.

Assume we have a chain object holding a point and we want to delete the object from the chain without deleting the point. Direct usage of chain->delete may destroy the point. The following code avoids this:

send(Point, lock_object, @on),
send(Chain, delete, Point),
get(Point, unlock, _).