diff options
| author | 2024-12-28 22:51:33 -0500 | |
|---|---|---|
| committer | 2024-12-28 22:51:33 -0500 | |
| commit | 641e8ad61257e969ff235b90c163691e2011c5e3 (patch) | |
| tree | b0f2dc83dbbfb2f8beb07d5541195a89775fc01f /mcgoron.iterator.string.scm | |
| parent | more list work (diff) | |
refactor string exceptions
Diffstat (limited to 'mcgoron.iterator.string.scm')
| -rw-r--r-- | mcgoron.iterator.string.scm | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/mcgoron.iterator.string.scm b/mcgoron.iterator.string.scm index 762b79d..62f10c4 100644 --- a/mcgoron.iterator.string.scm +++ b/mcgoron.iterator.string.scm @@ -76,21 +76,23 @@ (string-cursor<? x-cur y-cur))) #f))) +(define (string-constructor-exception obj) + (make-iterator-exception #f + 'string-constructor + (list (cons 'obj obj)))) + (define-syntax define-for-iterator-or-string ;; Define a function such that the first argument can either be a string ;; or a string iterator. The string iterator has its string extracted ;; before use. (syntax-rules () ((_ (name str args ...) body ...) - (define (name object args ...) - (define (internal str args ...) - body ...) - (cond - ((string? object) (internal object args ...)) - ((string-iterator? object) (internal (string-iterator-str object) - args ...)) - (else (raise (string-iterator-constructor-exception - object)))))))) + (define (name str args ...) + (let ((str (cond + ((string? str) str) + ((string-iterator? str) (string-iterator-str str)) + (else (raise (string-constructor-exception str)))))) + body ...))))) (define-for-iterator-or-string (string-iterator-start str) (string-iterator str (string-cursor-start str))) |
