mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Improve macro definition.
It's more robust to use `let' to have the macro result in its own new scope. (Unrelated to the hygiene point, of course.)
This commit is contained in:
parent
e8f8e2331b
commit
d8989c2ae3
@ -423,8 +423,7 @@ vec ; => #(1 2 3 4)
|
|||||||
|
|
||||||
;; Macros are hygienic, you cannot clobber existing variables!
|
;; Macros are hygienic, you cannot clobber existing variables!
|
||||||
(define-syntax-rule (swap x y)
|
(define-syntax-rule (swap x y)
|
||||||
(begin
|
(let ([tmp x])
|
||||||
(define tmp x)
|
|
||||||
(set! x y)
|
(set! x y)
|
||||||
(set! y tmp)))
|
(set! y tmp)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user