8.4 Class variables in User Defined Classes

Class-variables are declared, similar to instance-variables. through macro-expansion inside the :- pce_begin_class/[2,3] ... :- pce_end_class/0 definition of a class. The syntax is:

class_variable(<name>, <type>, <default>, [<summary>]).

<default> defines the value if not overruled in the Defaults file. It is a Prolog term describing an object similar to the arguments of send/[2-12].

In the following example. there is a class with the property `expert_level'. The program defines the default level to be novice. The user may change that in his/her personal Defaults file or change it while the application is running. As the value may change at runtime, there should be an instance- as well as a class-variable. Below is the skeleton for this code:

variable(expert_level, {novice,advanced,expert}, get,
         "Experience level of the user").

class_variable(expert_level, @default, novice).

expert_level(Obj, Level:{novice,advanced,expert}) :->
        send(Obj, slot, expert_level, Level),
        <handle changes>.

        (   get(Obj, expert_level, expert)
        ->  ...
        ;   ...