diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-29 20:13:43 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-29 20:13:43 -0700 |
commit | afb400eff15e7c77c5dd0fa5e35d91173f8df1ad (patch) | |
tree | b29f3217396cdc2b04a55a16721f81d6ce4f43ba /txr.1 | |
parent | 111650e235ab2e529fa1529b1c9a23688a11cd1f (diff) | |
download | txr-afb400eff15e7c77c5dd0fa5e35d91173f8df1ad.tar.gz txr-afb400eff15e7c77c5dd0fa5e35d91173f8df1ad.tar.bz2 txr-afb400eff15e7c77c5dd0fa5e35d91173f8df1ad.zip |
struct :init :fini specifiers.
* share/txr/stdlib/struct.tl (defstruct): New (:init ...) and
(:fini ...) syntax can be used in the slot list to specify
an initialization function and a gc-finalization function.
* txr.1: Documented.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -17835,6 +17835,64 @@ Such functions are called using the syntax which doesn't insert the instance name into the argument list. +.meIP (:init <> ( param ) << body-form *) +The +.code :init +descriptor doesn't describe a slot. Rather, it specifies code +which is executed when a structure is instantiated, after +the slot initializations specific to the structure type +are performed. The code consists of +.metn body-form -s +which are evaluated in order in a lexical scope in +which the variable +.meta param +is bound to the structure object. + +The +.code :init +specifier may not appear more than once in a given +.code defstruct +form. + +When an object with one or more levels of inheritance +is instantiated, the +.code :init +code of a base structure type, if any, is executed +before any initializations specific to a derived +structure type. + +Initializers in base structures must be careful about assumptions about slot +kinds, because derived structures can alter static slots to instance slots or +vice versa. To avoid an unwanted initialization being applied to the +wrong kind of slot, initialization code can be made conditional on the +outcome of +.code static-slot-p +applied to the slot. +(Code generated by +.code defstruct +for initializing instance slots performs this kind of check). + +.meIP (:fini <> ( param ) << body-form *) +The +.code :fini +descriptor doesn't describe a slot. Rather, it specifies +a finalization function which is associated with the +structure instance, as if by use of the +.code finalize +function. This finalization registration takes place +as the last step when an instance of the structure +is created, after the slots are initialized and +the +.code :init +code, if any, has been executed. The registration +takes place as if by the evaluation of the form +.cblk +.meti (finalize << obj (lambda <> (param) << body-form ...)) +.cble +where +.meta obj +denotes the structure instance. + .RE .PP |