2010/11/19 Felix <[email protected]>: > From: Thomas Chust <[email protected]> >> [...] >> in my opinion this library is a good idea. A feature I would like to see in >> this >> kind of library would be some comprehension mechanism (similar to SRFI-42 or >> Racket's for comprehensions). > > I guess this would probably be suited for a separate extension. Ideally, > one could try to extend SRFI-42 to handle this, even though doing so > requires digging into its implementation, which appears frightningly > complex... > [...]
Hello, ok, arguably comprehensions do belong into a separate library. After all, the functionality of SRFI-42 and the sequences library has significant overlap. For what it's worth, I think integrating the sequences library with SRFI-42 is trivial, though, because SRFI-42 is very conveniently extensible. An implementation of a sequences based iterator for SRFI-42 is attached for anyone who wants to play around with it :-) I also encountered another weird behaviour that I consider a bug: The expression (at-end? (iterator '())) evaluates to #f, which ultimately results in iterators over lists never detecting the end of the list when they are stepped through! Ciao, Thomas -- When C++ is your hammer, every problem looks like your thumb.
(require-library srfi-42 sequences) (module srfi-42-sequences (:seq) (import scheme chicken srfi-42 (rename sequences [index iterator-index])) (define-syntax :seq (syntax-rules (index) [(:seq cc var (index idx) arg) (:do cc (let ([seq arg])) ([itr (iterator seq)]) (not (at-end? itr)) (let ([var (elt seq itr)] [idx (iterator-index itr)])) #t ((advance! itr)))] [(:seq cc var (index idx) arg ...) (:seq cc var (index idx) (append (coerce '() arg) ...))] [(:seq cc var arg) (:do cc (let ([seq arg])) ([itr (iterator seq)]) (not (at-end? itr)) (let ([var (elt seq itr)])) #t ((advance! itr)))] [(:seq cc var arg ...) (:seq cc var (append (coerce '() arg) ...))])) )
_______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
