This mechanism is most often used to obtain a reference to the current module instance with a restriction of its module type to a compatible subtype (eg, containing a subset of the current module's declarations). For example, given modules of the following types:
T: module { init: fn(nil: ref Draw->Context, nil: list of string); special: fn(a, b: int); }; S: module { special: fn(x, y: int); }; G: module { init: fn(v: S); };
an instance of module T can execute both the following:
t := load T SELF; s := load S SELF;
but a module of type S could not load itself as type T.
The result might typically be assigned to a module variable of that type (including passing as a parameter or storing in an adt), as in:
g := load G "g.dis"; g->init(s);
See the definition and use of BufioFill in bufio(2) and bufio-chanfill(2) for a practical example.
SYS-SELF(2 ) | Rev: Tue Mar 31 02:42:39 GMT 2015 |