We introduce the syntax for user-defined classes using a skeleton. Except for the pce_begin_class/[2,3] and pce_end_class/0, everything in the skeleton is optional and may be repeated multiple times. The order of declarations is not important, but the order of the skeleton is the proposed order. An exception to this rule is the pce_group/1 directive, that may be placed anywhere and defines the group-identifier for the declarations that follow. The skeleton is given in figure 14.
:- use_class_template(<TemplateClass>).
:- send(@class, <Selector>{, <Arg>}).
:- pce_class_directive(<Goal>).
variable(<Name>, <Type>[:= <Value>], <Access> [, <Summary>]).
delegate_to(<VarName>).
class_variable(<Name>, <Type>, <Default> [, <Summary>]).
handle(<X>, <Y>, <Kind>, <Name>).
:- pce_group(<Group>).
<SendSelector>(<Receiver>{, <Arg>[:[<AName>=]<Type>]}) :->
[<Summary>::]
<PrologBody>.
<GetSelector>(<Receiver>{, <Arg>[:[<AName>=]<Type>]}, <RVal>[:<Type>]) :<-
[<Summary>::]
<PrologBody>.
:- pce_end_class.
Figure 14 : Skeleton for user-defined classes |
The class-name may be followed by a list of TermNames that
define the result of object/2. object/2
unifies its second argument with a term whose functor is the name of the
class and whose arguments are the result of a `get' operation using the TermName
as selector. For example, point(x,y) specifies that object(P, T)
unifies
T to a term point /2 with the <-
x and <-
y
of the point instance as arguments. When omitted, the term-description
of the super-class is inherited.
->
_save_in_file'.
:- send(@class, save_style_variable, nil).
See also pce_class_directive/1 and section 7.5.3.
new(NewTerm)
to force each
instance to create its own unique copy of the initial value. Access
defines which implicit universal methods will be associated
with the variable. A universal method is defined to be a method that
reads or writes the slot, without performing any additional actions. See
also section 7.2.Defaults
file.
See
chapter 8 for details.
The Default entry describes the default value if there is no
value specified in the Defaults
file. Example:
class_variable(size, size, size(400,200), "Default size of object").
:- send(@class, handle, handle(X, Y, Kind, Name)).
<->
group'
attribute of any variable or method definition following this directive.
Groups are used to organise methods by the ClassBrowser. Groups have no
semantic implications.
:- pce_group(@default).
makes methods inherit their group from the method that is re(de)fined.
If no method is re(de)fined, the group will be miscellaneous.
Table table 6 describes the details of the non-terminals in the above skeleton in more detail. The notation is an incomplete BNF notation.
<Meta> | ::= | <Name> | Name of the class this class will be an instance of. Default is the meta-class of the super-class |
<Class> | ::= | <Name> | Name of the class to be defined |
<TermName> | ::= | <Name> | Selector name to fetch object/2 argument. For example, a point is translated into point(<X>, <Y>) and the description is point(x,y) |
<Super> | ::= | <Name> | Name of the super-class. object refers to the most general class |
<Summary> | ::= | "{<Char>}" | Summary description as appearing in the online manual. < 40 characters, no newlines, Prolog string |
<TemplateClass> | ::= | <Name> | Import a template class. See section 7.5.2.1 |
<Selector> | ::= | <Name> | Name of a method |
<X> | ::= | <IntExpr> | See class handle |
<Y> | ::= | <IntExpr> | See class handle |
<Kind> | ::= | <Name> | Category indicator. See class handle |
<Access> | ::= | both | get | send | none
| Defines the access right to this variable |
<VarName> | ::= | <Name> | Name of variable used for delegation |
<Group> | ::= | <Name> | Functional group of the following methods or variables. Used to organise the ClassBrowser |
<SendSelector> | ::= | <Name> | Name of send-method to define |
<GetSelector> | ::= | <Name> | Name of get-method to define |
<Receiver> | ::= | <Variable> | Prolog variable bound to the receiver |
<Arg> | ::= | <Variable> | Prolog variable bound to argument |
<RVal> | ::= | <Variable> | Prolog variable that should be bound to the return value |
<AName> | ::= | <Name> | XPCE name for named argument |
<Type> | See section 3.2.1 and section 7.5.1 | ||
<PrologBody> | Ordinary Prolog code | ||
<Value> | Initial value for the instance variable. At this moment, only using constants is supported (int, name, bool) |
Table 6 : Syntax details for User Defined Classes |