The Larch/C++ keyword this
can only be used in the
specification of a member function.
It has the same meaning as it does in C++
(see Section r.9.3.1 in [Stroustrup91]).
When used in a (non-const
) member function of class T
,
which is associated with sort ValT
(often valT
is just T
, but see section 2.7 Types and Sorts),
this
has sort ConstObj[Ptr[Obj[ValT]]]
.
When used in a const
member function,
the sort is ConstObj[Ptr[ConstObj[ValT]]]
.
For example, in the specification of a member function of
a class Person
(see section 7.1.1 A First Class Design (Person)
for more details on this example),
the sort of this
is ConstObj[Ptr[Obj[Person]]]
.
However, in the specification of a const
member function
of class Person
,
such as years_old
,
the sort of this
is
ConstObj[Ptr[ConstObj[Person]]]
.
The Larch/C++ keyword self
is a shorthand for (*(this\any))
,
which is dereferencing the pointer value found in this
in some
visible state.
See section 6.2.1 State Functions for details about the state-function \any
(and see section 6.2 Mutation for the notion of state.)
(Any visible state is acceptable, because the this
pointer itself
cannot be assigned to in a C++ program.)
Thus a form such as self^
is shorthand for (*(this\any))^
.
The keyword self
can only be used in the specification of a member
function.
When used in a member function of class T
,
which is associated with sort ValT
,
self
has sort Obj[ValT]
.
Most often self
is much more convenient for specification
than this
.
For example, in the specification of a member function of
a class Person
(see section 7.1.1 A First Class Design (Person)
for more details on this example),
the sort of self
is Obj[Person]
.
However, in the specification of a const
member function
of class Person
,
such as years_old
,
the sort of self
is
ConstObj[Person]
.
See section 7 Class Specifications for more examples.
Go to the first, previous, next, last section, table of contents.