|(require (planet neil/srfi-9-plus:1:=1))|
The srfi-9-plus library (almost completely) implements SRFI-9, and adds a define-record-type/write syntax that is like define-record-type but extended to define a custom writer.
This library does not completely implement SRFI-9 in that the define-record-type defined here requires that the sequence of field tags in the constructor match the initial sequence of field tags defined by the field specs. That feature of SRFI-9 should not be necessary, since the field specs can be ordered to match the desired constructor arguments.
This library was written for adding custom writing to some code that was implemented using SRFI-9, rather than rework that code to use define-struct or make-struct-type directly. srfi-9-plus is currently implemented for Racket as a veneer over make-struct-type, although that is not guaranteed.
This documentation was written quickly.
|(define-record-type/write type constructor-spec predicate write-proc field-specs ...)|
This is like SRFI-9 define-record-type, except for the extra write-proc form, which is a Racket struct prop:custom-write procedure. For example:
(define (foo-write-proc record port write?) (and write? (display "<<<foo " port)) (write (foo:aaa record) port) (display " to " port) (write (foo:bbb record) port) (and write? (display ">>>" port))) (define-record-type/write foo (make-foo aaa bbb) foo? foo-write-proc (aaa foo:aaa) (bbb foo:bbb foo:set-bbb!) (ccc foo:ccc)) (define x (make-foo 0 60)) x ==> <<<foo 0 to 60>>> (format "~A" x) ==> "0 to 60"
|(define-record-type type constructor-spec predicate field-specs ...)|
This is like the SRFI-9 syntax of the same name.
Version 0.2 —
2011-08-22 — PLaneT (1 1)
Fixed a symbol in an error message. Fixed typo in documentation. Changed references to Scheme to Racket.
Version 0.1 —
2009-11-28 — PLaneT (1 0)
Initial version. Tested lightly.
Copyright (c) 2009 – 2011 Neil Van Dyke. This program is Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License (LGPL 3), or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.
Standard Documentation Format Note: The API signatures in this documentation are likely incorrect in some regards, such as indicating type any/c for things that are not, and not indicating when arguments are optional. This is due to a transitioning from the Texinfo documentation format to Scribble, which the author intends to finish someday.