| 1 |
#!r6rs |
| 2 |
;; Copyright (C) William D Clinger 2008. All Rights Reserved. |
| 3 |
;; |
| 4 |
;; Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
;; of this software and associated documentation files (the "Software"), to deal |
| 6 |
;; in the Software without restriction, including without limitation the rights |
| 7 |
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 |
;; copies of the Software, and to permit persons to whom the Software is |
| 9 |
;; furnished to do so, subject to the following conditions: |
| 10 |
;; |
| 11 |
;; The above copyright notice and this permission notice shall be included in |
| 12 |
;; all copies or substantial portions of the Software. |
| 13 |
;; |
| 14 |
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. REMEMBER, THERE IS NO |
| 17 |
;; SCHEME UNDERGROUND. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 18 |
;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 |
;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 20 |
;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
|
| 22 |
(library (srfi :99 records inspection) |
| 23 |
|
| 24 |
(export record? record-rtd |
| 25 |
rtd-name rtd-parent |
| 26 |
rtd-field-names rtd-all-field-names rtd-field-mutable?) |
| 27 |
|
| 28 |
(import (rnrs base) |
| 29 |
(rnrs lists) |
| 30 |
(rnrs records inspection) |
| 31 |
(srfi :99 records helper)) |
| 32 |
|
| 33 |
; The record? predicate is already defined by (rnrs records inspection). |
| 34 |
|
| 35 |
; The record-rtd procedure is already defined by (rnrs records inspection). |
| 36 |
|
| 37 |
(define rtd-name record-type-name) |
| 38 |
|
| 39 |
(define rtd-parent record-type-parent) |
| 40 |
|
| 41 |
(define rtd-field-names record-type-field-names) |
| 42 |
|
| 43 |
(define (rtd-all-field-names rtd) |
| 44 |
(define (loop rtd othernames) |
| 45 |
(let ((parent (rtd-parent rtd)) |
| 46 |
(names (append (vector->list |
| 47 |
(rtd-field-names rtd)) |
| 48 |
othernames))) |
| 49 |
(if parent |
| 50 |
(loop parent names) |
| 51 |
(list->vector names)))) |
| 52 |
(loop rtd '())) |
| 53 |
|
| 54 |
(define (rtd-field-mutable? rtd0 fieldname) |
| 55 |
(define (loop rtd) |
| 56 |
(if (rtd? rtd) |
| 57 |
(let* ((names (vector->list (rtd-field-names rtd))) |
| 58 |
(probe (memq fieldname names))) |
| 59 |
(if probe |
| 60 |
(record-field-mutable? rtd (- (length names) (length probe))) |
| 61 |
(loop (rtd-parent rtd)))) |
| 62 |
(assertion-violation 'rtd-field-mutable? |
| 63 |
"illegal argument" rtd0 fieldname))) |
| 64 |
(loop rtd0)) |
| 65 |
|
| 66 |
) |