Skip to content

Instantly share code, notes, and snippets.

@soegaard
Created July 26, 2012 13:46
Show Gist options
  • Save soegaard/3182110 to your computer and use it in GitHub Desktop.
Save soegaard/3182110 to your computer and use it in GitHub Desktop.
for/first in terms of for/fold without let/ec
#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