In the majority of code written using Lpp, Lpp objects appear as type
let. All operations within Lpp objects are done with
accessors. When defining new Lpp objects the user needs to get at the
internals of such objects for defining his own accessors. The Lpp
the macro makes it easy and safe to access the internals of an
Lpp object.
| the name exp | Macro |
| theOrNil name exp | Macro |
| asThe name exp | Macro |
| fromThe name exp | Macro |
The argument name names some subtype of the Lpp type hierarchy.
Lpp takes the liberty to adapt the Common Lisp the construct.
Much like Common Lisp the Lpp the macro evaluates the given
expression exp and returns the value if it is of the type named
by the given name and triggers an exception if the type is not
of the given name. In addition the Lpp the macro
returns a pointer to that object of type name name. This is a
specific pointer of that name type as opposed to the more
general Lpp let type. For example:
classL(MyType) {
int slot1;
public: friend void setSlot1(let, int);};
setSlot1(makeInstance(MyType), 25);
void setSlot1(let x, int val) { // x is input as general let type
MyType* mt = the(MyType, x); // mt is now a specific pointer
mt->slot1 = val;} // to a MyType object
The the macro enforces that the given object is of type
type by doing a dynamic type check. Dynamic type checking can
be turned off per compilation unit, See Type Checking.
The asThe macro is the same as the but never does any
type checking. It is useful when a function absolutely knows what the
type of an Lpp object is. The fromThe macro is the same as
asThe but instead demands that the object is of the given type
or derived from a supertype of the given type. It is useful when a
function absolutely knows what the type or supertype of an Lpp object
is. The theOrNil macro is the same as the but also
allows nil to pass as the type.