P: (# A: (# X: ^P; (* reference to item qualified by P *) B: ^|P (* reference to component qualified by P *) do this(P) -> X; (* legal use of this(P) *) this(P) -> R; (* illegal use of this(P) *) #)
The compiler assumes that this(P) is a reference to an item object. Since an item reference cannot be assigned to a component reference the evaluation this(P) -> R is illegal.
It is, however, possible to use a run-time routine to convert an item reference to a component reference, provided that the item is part of a component. Consider:
When X is executed, the P-object is part of the component X and objectToComponent will return a reference to X.
(# P: (# B: |^ P do this(P) -> objectToComponent -> B #); X: |@ P; Y: @ P; do X; (* OK *) Y; (* a run-time error will happen *) #)
When Y is executed, the P-object is not part of a component and objectToComponent will fail.
It is also possible to get a reference to the item-part of a component by using the pattern componentToObject as shown in:
X -> componentToObject
The patterns objectToComponent and componentToObject are placed in the library:
|BETA Language Modifications - Reference Manual||© 1999-2002 Mjølner Informatics||
[Modified: Sunday October 22nd 2000 at 0:53]