Created
September 24, 2012 03:18
-
-
Save dyoo/3774030 to your computer and use it in GitHub Desktop.
for/seq for sequence generating through for loops
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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