classprologswi-prologparametric-polymorphismlogtalk

Extending and/or parametric object as attribute


As I understand now from Array as object I have to use parametric object, because using non-parametric Logtalk objects implies that I have to use assert i.e. any change/set rewrites the whole array.

The problem is then :

Point 1

:- object(a2d, instantiates(array)).

:- end_object.

even if it works, how do u access it internally .

Point2

means modifying the Term somehow ?


Solution

  • In that parametric object solution, the object is used to encapsulate the predicates working on the array representation and object parameter is used to hold the (compound) term representing an array itself.

    The parametric object, a prototype in this case, can be extended as any other prototype:

    :- object(a2d(_Array_), extends(array(_Array_)).
    
    :- end_object.
    

    Note that the identifier of the parametric object is array(_) (i.e. a compound term). Thus, array(_) and array are identifiers for different objects.