mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-07 07:16:42 +02: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:
@@ -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)))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user