diff options
| author | 2024-12-28 22:29:28 -0500 | |
|---|---|---|
| committer | 2024-12-28 22:29:28 -0500 | |
| commit | d80be95f5e58f761f2a215256150c85fea8c9d75 (patch) | |
| tree | 98bd3893ba5b40ecb8043d4cbcc12c3288062e84 /mcgoron.iterator.base.scm | |
| parent | refactor iterators to be closure objects (diff) | |
refactor exceptions to be less verbose
Diffstat (limited to 'mcgoron.iterator.base.scm')
| -rw-r--r-- | mcgoron.iterator.base.scm | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/mcgoron.iterator.base.scm b/mcgoron.iterator.base.scm index f823289..21af871 100644 --- a/mcgoron.iterator.base.scm +++ b/mcgoron.iterator.base.scm @@ -31,16 +31,20 @@ (define-syntax define-iterator-implementation (syntax-rules (else) - ((_ (cstr cstr-args ...) ((name . formal) body ...) ...) + ((_ (cstr cstr-args ...) self ((name . formal) body ...) ...) (define (cstr cstr-args ...) - (make-iterator-container - (lambda (type args) - (case type - ((name) (apply (lambda formal body ...) args)) - ... - (else (raise (not-implemented-exception type args))))) - '(name ...) - (quote cstr)))))) + (letrec ((self + (make-iterator-container + (lambda (type args) + (case type + ((name) (apply (lambda formal body ...) args)) + ... + (else (raise (not-implemented-exception self + type + args))))) + '(name ...) + (quote cstr)))) + self))))) (define-invocation iterator-at-start?) (define-invocation iterator-at-end?) @@ -49,3 +53,7 @@ (define-invocation iterator-set! val) (define-invocation iterator->index) +(define (iterator-next itr) + (iterator-advance itr 1)) +(define (iterator-prev itr) + (iterator-advance itr -1)) |
