diff --git a/index.html b/index.html index c29adfe..3ce6c7b 100644 --- a/index.html +++ b/index.html @@ -187,8 +187,10 @@ audience I’m writing for, you don’t know them yet. You can skip learning them now. (Someday if you want to understand someone else’s older macros, you can learn about them then.)
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