Added some generator clauses to the iterators
in-vector, in-string and all other indexed for clauses now have generator clauses. in-hash now has a generator clause.
This commit is contained in:
parent
79b7c4eedd
commit
f0900a0497
1 changed files with 29 additions and 4 deletions
|
@ -126,12 +126,35 @@
|
|||
(define-syntax in-type
|
||||
(syntax-rules ()
|
||||
((in-type seq next . rest)
|
||||
(%in-idx >= (lambda (x i) (+ i 1)) (lambda (x) 0) length ref tmp seq next . rest))))
|
||||
(%in-idx >= (lambda (x i) (+ i 1)) (lambda (x) 0) length ref tmp seq next . rest))
|
||||
((_ coll)
|
||||
(in-indexed-generator coll length ref))))
|
||||
(define-syntax in-type-reverse
|
||||
(syntax-rules ()
|
||||
((in-type-reverse seq next . rest)
|
||||
(%in-idx < (lambda (x i) (- i 1)) (lambda (x) (- (length x) 1)) (lambda (x) 0) ref tmp seq next . rest))))
|
||||
))))
|
||||
(%in-idx <
|
||||
(lambda (x i) (- i 1))
|
||||
(lambda (x) (- (length x) 1))
|
||||
(lambda (x) 0) ref tmp seq next . rest))
|
||||
((_ coll)
|
||||
(in-indexed-generator-reverse coll length ref))))))))
|
||||
|
||||
(define (in-indexed-generator coll len ref)
|
||||
(let ((index -1)
|
||||
(length (len coll)))
|
||||
(lambda ()
|
||||
(set! index (+ index 1))
|
||||
(if (>= index length)
|
||||
(eof-object)
|
||||
(ref coll index)))))
|
||||
|
||||
(define (in-indexed-generator-reverse coll len ref)
|
||||
(let ((index (len coll)))
|
||||
(lambda ()
|
||||
(set! index (- index 1))
|
||||
(if (< index 0)
|
||||
(eof-object)
|
||||
(ref coll index)))))
|
||||
|
||||
(define-in-indexed in-vector in-vector-reverse vector-length vector-ref)
|
||||
|
||||
|
@ -291,7 +314,9 @@
|
|||
((not (pair? cursor)))
|
||||
((bindings (car cursor)))
|
||||
()
|
||||
. rest))))
|
||||
. rest))
|
||||
((_ hash-expr)
|
||||
(in-list (hash-map->list cons hash-expr)))))
|
||||
|
||||
|
||||
(define-syntax accumulating
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue