This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Maciej Stachowiak <mstachow@mit.edu> writes: [ snip ] > Iterators are very un-Schemely, IMO, Scheme is not in the business of > telling you how to iterate. Huh? According to one classification I've seen, there are two kinds of iterators: 1) "Internal" iterators - those that _do_ tell you how to iterate. Scheme has, for example, `for-each', which is an internal list iterator. 2) "External" iterators - those that _do_not_ tell you how to iterate. What is so un-Schemely about the following snippet? --------------->8 cut cut 8<----------------- (define (p e) (display e) (newline)) (define l-range (list->i-range '(la lb lc))) (define v-range (vector->i-range '#(va vb vc))) (for-each/i-range p (car l-range) (cdr l-range)) ==> la lb lc (for-each/i-range p (car v-range) (cdr v-range)) ==> va vb vc --------------->8 cut cut 8<----------------- Here is the readable definition of `for-each/i-range': (define (for-each/i-range proc first last) (let loop ((current first)) (if (not (i=? current last)) (begin (proc (i-ref current)) (loop (++i current)))))) And here is the actual definition (uglier but not so garbage-generating): (define (for-each/i-range proc first last) (let loop ((current (clone-i first))) (if (not (i=? current last)) (begin (proc (i-ref current)) (loop (++i! current)))))) [ snip ] > - Maciej mike.