Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax-rules not completely hygienic?

I understand that syntax-rules is a hygienic macro system, but I do not understand why this happens:

(define not (lambda (x) x))

(define-syntax nand
  (syntax-rules ()
    ((_ a b)
     (not (and a b)))))

(nand #f #t)

==> #f

Now, if I had redefined not after defining the macro, then (nand #f #t) returns #t. Why, if the macro system is supposed to be hygienic?

like image 490
josh Avatar asked Jan 19 '12 14:01

josh


1 Answers

The macro is expanded in the environment that existed at the time the macro was defined, not in the environment that existed at the time the macro was called. This has nothing to do with hygiene, which is the property that variables introduced by the macro are distinct from other variables with the same name that exist elsewhere in the program.

like image 66
user448810 Avatar answered Sep 29 '22 05:09

user448810