Skip to content

@dyoo /for-seq.rkt
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
for/seq for sequence generating through for loops
#lang racket
(require racket/generator)
(define-syntax (for/seq stx)
(syntax-case stx ()
[(_ clauses . body)
#`(in-generator
(for/fold/derived #,stx
()
clauses
(define d (let () . body))
(yield d)
(values)))]))
(define seq1 (for/seq ([i (in-range 3)]
[j (in-list '(a b c))])
(displayln "here")
(list j (* i i))))
(define-syntax (for*/seq stx)
(syntax-case stx ()
[(_ clauses . body)
#`(in-generator
(for*/fold/derived #,stx
()
clauses
(define d (let () . body))
(yield d)
(values)))]))
(define seq2 (for*/seq ([i (in-range 3)]
[j (in-list '(a b c))])
(displayln "here")
(list j (* i i))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.