Next: iklib records defs consig, Previous: iklib records defs super-proto, Up: iklib records defs [Index]
In a use of the syntax define-record-type, the definition
clause:
(destructor-protocol ?expr)
allows the specification of an expression ?expr which must evaluate to the destructor protocol function; this function is used as explained below to construct a destructor function to be called:
delete syntax.
iklib records final for further details.
Here is how the destructor function is built:
destructor-protocol clause and no parent:
?expr must evaluate to a closure object accepting no arguments and
returning a closure object acting as destructor function for records of
this type. For example:
(define-record-type <port>
(fields port)
(destructor-protocol
(lambda ()
(lambda (record)
(close-port (<port>-port record))))))
destructor-protocol clause and a parent
specified with the parent or parent-rtd clauses:
?expr must evaluate to a closure object accepting as single
argument the parent’s destructor function and returning as single value
a closure object acting as destructor function for records of this type.
For example:
(define-record-type <port>
(fields port)
(destructor-protocol
(lambda ()
(lambda (record)
(close-port (<port>-port record))))))
(define-record-type <file>
(parent <port>)
(fields filename)
(destructor-protocol
(lambda (destroy-<port>)
(lambda (record)
(destroy-<port> record)))))
notice that the destructor of ‘<file>’ is meant to call the destructor of its supertype ‘<port>’ at some point; however calling the supertype’s destructor is optional.
destructor-protocol clause, it has a parent
and the parent has a destructor function: the parent’s destructor
function becomes this type’s destructor function.
The destructor function must return zero values (for example using (values) in tail
position).
Next: iklib records defs consig, Previous: iklib records defs super-proto, Up: iklib records defs [Index]