aboutsummaryrefslogtreecommitdiffstats
path: root/generic-iterator.scm
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2024-12-23 23:42:21 -0500
committerGravatar Peter McGoron 2024-12-23 23:42:21 -0500
commita7424d5838f3c6a2afefa49fc0fbe76a88596b6a (patch)
tree39fd7197dda091035eb7e18a08f99f22d066c810 /generic-iterator.scm
parentstring-iterator: use external function to simplify iterative application of p... (diff)
make iterator-advance only take integers
Diffstat (limited to '')
-rw-r--r--generic-iterator.scm27
1 files changed, 17 insertions, 10 deletions
diff --git a/generic-iterator.scm b/generic-iterator.scm
index 3c76400..ee5ac9e 100644
--- a/generic-iterator.scm
+++ b/generic-iterator.scm
@@ -29,17 +29,23 @@
(comparison get-comparison-procedure)
(private iterator-get-private))
+(define-syntax define-with-field-of-iterator
+ (syntax-rules ()
+ ((_ (name field args ...) emsg body ...)
+ (define (name iterator args ...)
+ (let ((field (field iterator)))
+ (if (not field)
+ (error emsg iterator args ...)
+ (begin body ...)))))))
+
;;; Define a function that invokes a field of the iterator on the data
;;; object inside the iterator and any other arguments supplied to the
;;; function.
(define-syntax define-invoke-field-of-iterator
(syntax-rules ()
- ((define-invoker name field-accessor emsg args ...)
- (define (name iterator args ...)
- (let ((proc (field-accessor iterator)))
- (if (not proc)
- (error emsg iterator)
- (proc args ...)))))))
+ ((_ name field-accessor emsg args ...)
+ (define-with-field-of-iterator (name field-accessor args ...) emsg
+ (field-accessor args ...)))))
(define-invoke-field-of-iterator iterator-at-start?
get-start-predicate
@@ -48,10 +54,11 @@
get-end-predicate
"no end predicate")
-(define-invoke-field-of-iterator iterator-advance
- get-advance
- "no procedure to move iterator"
- spaces)
+(define-with-field-of-iterator (iterator-advance get-advance spaces)
+ "no advance procedure"
+ (if (not (integer? spaces))
+ (error "must advance an integer amount" spaces)
+ (get-advance spaces)))
(define-invoke-field-of-iterator iterator-ref
get-ref