1 Introduction
2 Interface
define-record-type/ write
3 History
4 Legal
Version: 0.2

srfi-9-plus: Enhanced define-record-type in Racket

Neil Van Dyke

License: LGPL 3   Web: http://www.neilvandyke.org/srfi-9-plus/

 (require (planet neil/srfi-9-plus:1:=1))

1 Introduction

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.

2 Interface

(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)
  (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.

3 History

4 Legal

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.