Created
July 26, 2012 13:46
-
-
Save soegaard/3182110 to your computer and use it in GitHub Desktop.
for/first in terms of for/fold without let/ec
This file contains 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 | |
(define-syntax (my-for/first stx) | |
(syntax-case stx () | |
[(_ (for-clause ...) . defs+exprs) | |
(syntax/loc stx | |
(let-values ([(val _) | |
(for/fold ([val #f] [stop? #f]) | |
(for-clause ... #:unless stop?) | |
(begin | |
(define x (let () . defs+exprs)) | |
(values x #t)))]) | |
val))])) | |
(my-for/first ([x '(1 3 5 7 4 6)] | |
#:when (even? x)) | |
x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment