mes/lib/srfi/srfi-9.scm

45 lines
1.5 KiB
Scheme
Raw Normal View History

2016-07-23 12:39:33 +00:00
;; Copyright (c) 1993 by Richard Kelsey and Jonathan Rees. See file COPYING.
2016-07-23 11:13:21 +00:00
2016-07-23 12:39:33 +00:00
;; There's no implicit name concatenation, so it can be defined
;; entirely using syntax-rules. Example:
2016-07-23 22:14:40 +00:00
;; (define-record-type foo
2016-07-23 12:39:33 +00:00
;; (make-foo x y)
;; foo? - predicate name is optional
;; (x foo-x)
;; (y foo-y)
;; (z foo-z set-foo-z!))
2016-07-23 11:13:21 +00:00
2016-07-23 12:39:33 +00:00
;; Copyright (c) 1993-2004 by Richard Kelsey and Jonathan Rees. See file COPYING.
2016-07-23 11:13:21 +00:00
(define-syntax define-record-type
(syntax-rules ()
2016-07-23 22:14:40 +00:00
((define-record-type type
2016-07-23 12:39:33 +00:00
(constructor arg ...)
(field . field-stuff)
2016-07-23 11:13:21 +00:00
...)
2016-07-23 22:14:40 +00:00
(begin (define type (make-record-type 'type '(field ...)))
2016-07-23 12:39:33 +00:00
(define constructor (record-constructor type '(arg ...)))
(define-accessors type (field . field-stuff) ...)))
2016-07-23 22:14:40 +00:00
((define-record-type type
2016-07-23 12:39:33 +00:00
(constructor arg ...)
pred
more ...)
2016-07-23 22:14:40 +00:00
(begin (define-record-type type
2016-07-23 12:39:33 +00:00
(constructor arg ...)
more ...)
(define pred (record-predicate type))))))
;; Straightforward version
2016-07-23 11:13:21 +00:00
(define-syntax define-accessors
(syntax-rules ()
2016-07-23 12:39:33 +00:00
((define-accessors type field-spec ...)
(begin (define-accessor type . field-spec) ...))))
2016-07-23 11:13:21 +00:00
2016-07-23 12:39:33 +00:00
(define-syntax define-accessor
2016-07-23 11:13:21 +00:00
(syntax-rules ()
2016-07-23 12:39:33 +00:00
((define-accessor type field accessor)
(define accessor (record-accessor type 'field)))
((define-accessor type field accessor modifier)
(begin (define accessor (record-accessor type 'field))
(define modifier (record-modifier type 'field))))))