forsyth20121205-174063a80cc13 years agoHistory
83 lines · 1.6 KB · Text
RawDownload
.TH SYS-SELF 2.SH NAMESELF \- reference self as a compatible module type.SH SYNOPSIS.Binclude "sys.m";.br.BI "me := load" " Module " SELF;.SH DESCRIPTIONAn instance ofa module of one type can acquire a reference to itself as any compatible module type,using the Limbo.B loadoperator with the special built-in module name.BR $self .Normally, applications use a synonym, the constant.BR SELF ,which is defined by.B sys.m.I outsidethe declaration of the.B Sysmodule(so that it need not be imported).Note that the result of the.B loadrefers to the same instancethat is currently executing (ie, the same module data)..PPThis mechanism is most often used to obtain a reference to the current moduleinstance with a.I restrictionof its module type to a compatible subtype (eg, containing a subsetof the current module's declarations).For example, given modules of the following types:.IP.EXT: 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);};.EE.PPan instance of module.B Tcan execute both the following:.IP.EXt := load T SELF;s := load S SELF;.EE.PPbut a module of type.B Scould not load itself as type.BR T ..PPThe result might typically be assigned to a module variable of that type(including passing as a parameter or storing in an adt), as in:.IP.EXg := load G "g.dis";g->init(s);.EE.PPSee the definition and use of.B BufioFillin.IR bufio (2)and.IR bufio-chanfill (2)for a practical example..SH SEE ALSO``The Limbo Programming Language'', Volume 2.