| 1 |
#!r6rs |
| 2 |
;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named |
| 3 |
;; LICENSE from the original collection this file is distributed with. |
| 4 |
|
| 5 |
(library (srfi :37 args-fold) |
| 6 |
(export |
| 7 |
args-fold |
| 8 |
(rename (make-option option)) |
| 9 |
option? |
| 10 |
option-names |
| 11 |
option-required-arg? |
| 12 |
option-optional-arg? |
| 13 |
option-processor) |
| 14 |
(import |
| 15 |
(rnrs) |
| 16 |
(srfi private include)) |
| 17 |
|
| 18 |
|
| 19 |
(define-record-type option |
| 20 |
(fields |
| 21 |
names required-arg? optional-arg? processor) |
| 22 |
(protocol |
| 23 |
(lambda (c) |
| 24 |
(lambda (n ra oa p) |
| 25 |
(if (and |
| 26 |
(and (list? n) |
| 27 |
(positive? (length n)) |
| 28 |
(for-all (lambda (x) |
| 29 |
(or (and (string? x) (positive? (string-length x))) |
| 30 |
(char? x))) |
| 31 |
n)) |
| 32 |
(boolean? ra) |
| 33 |
(boolean? oa) |
| 34 |
(not (and ra oa)) |
| 35 |
(procedure? p)) |
| 36 |
(c n ra oa p) |
| 37 |
(assertion-violation 'option "invalid arguments" n ra oa p)))))) |
| 38 |
|
| 39 |
(define args-fold |
| 40 |
(let ((option make-option)) |
| 41 |
(include/resolve ("srfi" "%3a37") "srfi-37-reference.scm") |
| 42 |
args-fold)) |
| 43 |
) |