www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 65d06802cac532feffefabbb762e6f5a51c8a7ac
parent 9620db724eea4d9d60b27f690961b11d0fa3f5c3
Author: Greg Hendershott <greghendershott@gmail.com>
Date:   Fri,  2 Nov 2012 11:44:33 -0400

Re-org the (require (for-syntax racket/match)) example.

Diffstat:
Mmain.rkt | 30++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/main.rkt b/main.rkt @@ -496,21 +496,27 @@ We can write: (match (syntax->list stx) [(list name condition true-expr false-expr) (datum->syntax stx `(cond [,condition ,true-expr] - [else ,false-expr]))])) + [else ,false-expr]))]))] + +Great. Now let's try using it: + +@i[ (our-if-using-match #t "true" "false") ] -But wait, we can't. It's complaining that @racket[match] isn't -defined. We haven't required the @racket[racket/match] module? - -It turns out we haven't. Remember, this transformer function is -working at compile time, not run time. And at compile time, only -@racket[racket/base] is required for you automatically. If we want -something like @racket[racket/match], we have to require it -ourselves---and require it @italic{for compile time}. Instead of using -plain @racket[(require racket/match)], the way to say this is to use -@racket[(require (for-syntax racket/match))]---the @racket[for-syntax] -part meaning, "for compile time". +Oops. It's complaining that @racket[match] isn't defined. + +Our transformer function is working at compile time, not run time. And +at compile time, only @racket[racket/base] is required for you +automatically---not the full @racket[racket]. + +Anything beyond @racket[racket/base], we have to require +ourselves---and require it for compile time using the +@racket[for-syntax] form of @racket[require]. + +In this case, instead of using plain @racket[(require racket/match)], +we want @racket[(require (for-syntax racket/match))]---the +@racket[for-syntax] part meaning, "for compile time". So let's try that: