> You can make a new `define` form where `yield` means something different:
>

Ha that's really cool! I definitely need to read up more on the different
macro tricks. I'm new to Racket (my nearest experience is in Clojure), so
David's point about looking for idiomatic ways is well taken. There's
definitely some cool new things possible that I need to get used to.

With your define/ideal-world form, is there a way to test whether something
was created using that form? E.g. by generating a predicate like
ideal-world? That way I can make sure with a contract that my function gets
passed an ideal-world generator.

cheers,
Kees


>
>
> #lang racket
> (require (except-in racket/generator yield)
>          (prefix-in gen: (only-in racket/generator yield))
>          racket/stxparam)
>
> (define-syntax-parameter yield (λ (stx) #'"error: `yield` not
> parameterized"))
>
> (define-syntax (yield* stx)
>   (syntax-case stx ()
>     [(_ . vals)
>      #'(call-with-values (thunk (gen:yield . vals))
>                          (case-lambda
>                            [() (void)]
>                            [(v) (if (exn? v)
>                                     (raise v)
>                                     v)]
>                            [vs vs]))]))
>
> (define-syntax (define/ideal-world stx)
>   (syntax-case stx ()
>     [(_ ID . BODY)
>      #'(define ID
>          (syntax-parameterize ([yield (make-rename-transformer #'yield*)])
>            . BODY))]))
>
> (define/ideal-world mygenerator (generator ()
>                                            (with-handlers ([exn? (lambda
> (e) (yield 42))])
>                                              (yield 1)
>                                              (yield 2)
>                                              (yield 3))))
> (mygenerator)
>
> (mygenerator (exn:fail "Welp" (current-continuation-marks)))
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to