From 6d06141751f158b3d1a2699f6e4bc5ddb635e19c Mon Sep 17 00:00:00 2001
From: Greg Hendershott
The syntax variation of them works similarly. The idea is, we’ll define it to mean an error by default. Only inside of our -aif will it have a meaningful value:
> (require racket/stxparam)
> (define-syntax-parameter it (lambda (stx) (raise-syntax-error (syntax-e stx) "can only be used inside aif")))
> (define-syntax-rule (aif condition true-expr false-expr) (let ([tmp condition]) (if tmp (syntax-parameterize ([it (make-rename-transformer #'tmp)]) true-expr) false-expr))) > (aif 10 (displayln it) (void)) 10
> (aif #f (displayln it) (void))
We can still use it as a normal variable name:
> (define it 10) > it 10
If we try to use it outside of an aif form, and -it isn’t otherwise defined, we get an error like we want:
> (displayln it) 10
Perfect.
TO-DO.
Hopefully I will answer these in the course of the other sections. But +aif will it have a meaningful value:
> (require racket/stxparam)
> (define-syntax-parameter it (lambda (stx) (raise-syntax-error (syntax-e stx) "can only be used inside aif")))
> (define-syntax-rule (aif condition true-expr false-expr) (let ([tmp condition]) (if tmp (syntax-parameterize ([it (make-rename-transformer #'tmp)]) true-expr) false-expr))) > (aif 10 (displayln it) (void)) 10
> (aif #f (displayln it) (void))
If we try to use it outside of an aif form, and +it isn’t otherwise defined, we get an error like we want:
> (displayln it) it: can only be used inside aif
But we can still define it as a normal variable:
> (define it 10) > it 10
TO-DO. +TO-DO. +TO-DO.
Hopefully I will answer these in the course of the other sections. But just in case:
Done.
TO-DO.
TO-DO.
Eli Barzliay wrote a blog post, Writing ‘syntax-case’ Macros, which explains many key details. However it’s written diff --git a/main.rkt b/main.rkt index 2cc1b02..5ec7231 100644 --- a/main.rkt +++ b/main.rkt @@ -724,13 +724,6 @@ define @racket[it] to mean an error by default. Only inside of our (aif #f (displayln it) (void)) ] -We can still use @racket[it] as a normal variable name: - -@i[ -(define it 10) -it -] - If we try to use @racket[it] outside of an @racket[aif] form, and @racket[it] isn't otherwise defined, we get an error like we want: @@ -738,12 +731,20 @@ If we try to use @racket[it] outside of an @racket[aif] form, and (displayln it) ] -Perfect. +But we can still define @racket[it] as a normal variable: + +@i[ +(define it 10) +it +] + @; ---------------------------------------------------------------------------- @section{Robust macros: syntax-parse} +TO-DO. +TO-DO. TO-DO. @; ----------------------------------------------------------------------------