<s>
Hygienic	B-Application
macros	I-Application
are	O
macros	O
whose	O
expansion	O
is	O
guaranteed	O
not	O
to	O
cause	O
the	O
accidental	O
capture	O
of	O
identifiers	O
.	O
</s>
<s>
They	O
are	O
a	O
feature	O
of	O
programming	O
languages	O
such	O
as	O
Scheme	B-Language
,	O
Dylan	B-Language
,	O
Rust	B-Application
,	O
Nim	B-Application
,	O
and	O
Julia	B-Application
.	O
</s>
<s>
The	O
general	O
problem	O
of	O
accidental	O
capture	O
was	O
well	O
known	O
within	O
the	O
Lisp	B-Language
community	O
prior	O
to	O
the	O
introduction	O
of	O
hygienic	B-Application
macros	I-Application
.	O
</s>
<s>
Hygienic	B-Application
macros	I-Application
are	O
a	O
programmatic	O
solution	O
to	O
the	O
capture	O
problem	O
that	O
is	O
integrated	O
into	O
the	O
macro	O
expander	O
itself	O
.	O
</s>
<s>
'	O
s	O
1986	O
paper	O
that	O
introduced	O
hygienic	B-Application
macro	I-Application
expansion	O
,	O
inspired	O
by	O
the	O
terminology	O
used	O
in	O
mathematics	O
.	O
</s>
<s>
In	O
C	B-Language
,	O
this	O
problem	O
can	O
be	O
illustrated	O
by	O
the	O
following	O
fragment	O
:	O
</s>
<s>
Running	O
the	O
above	O
through	O
the	O
C	B-Language
preprocessor	I-Language
produces	O
:	O
</s>
<s>
Consider	O
this	O
Common	B-Language
Lisp	I-Language
macro	O
:	O
</s>
<s>
This	O
method	O
was	O
used	O
in	O
MacLisp	B-Language
,	O
where	O
a	O
function	O
named	O
gensym	O
could	O
be	O
used	O
to	O
generate	O
a	O
new	O
symbol	O
name	O
.	O
</s>
<s>
Similar	O
functions	O
(	O
usually	O
named	O
gensym	O
as	O
well	O
)	O
exist	O
in	O
many	O
Lisp-like	O
languages	O
,	O
including	O
the	O
widely	O
implemented	O
Common	B-Language
Lisp	I-Language
standard	O
and	O
Elisp	B-Operating_System
.	O
</s>
<s>
However	O
,	O
gensym	O
,	O
macro	O
facilities	O
,	O
and	O
standard	O
library	O
functions	O
are	O
sufficient	O
to	O
embed	O
hygienic	B-Application
macros	I-Application
in	O
an	O
unhygienic	O
language	O
.	O
</s>
<s>
Using	O
packages	O
such	O
as	O
in	O
Common	B-Language
Lisp	I-Language
,	O
the	O
macro	O
simply	O
uses	O
a	O
private	O
symbol	O
from	O
the	O
package	O
in	O
which	O
the	O
macro	O
is	O
defined	O
.	O
</s>
<s>
Furthermore	O
the	O
ANSI	B-Language
Common	I-Language
Lisp	I-Language
standard	I-Language
categorizes	O
redefining	O
standard	O
functions	O
and	O
operators	O
,	O
globally	O
or	O
locally	O
,	O
as	O
invoking	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
Thus	O
the	O
Lisp	B-Language
package	O
system	O
provide	O
a	O
viable	O
,	O
complete	O
solution	O
to	O
the	O
macro	O
hygiene	O
problem	O
,	O
which	O
can	O
be	O
regarded	O
as	O
an	O
instance	O
of	O
name	O
clashing	O
.	O
</s>
<s>
Hygienic	B-Application
macro	I-Application
systems	O
in	O
languages	O
such	O
as	O
Scheme	B-Language
use	O
a	O
macro	O
expansion	O
process	O
that	O
preserves	O
the	O
lexical	O
scoping	O
of	O
all	O
identifiers	O
and	O
prevents	O
accidental	O
capture	O
.	O
</s>
<s>
For	O
example	O
,	O
Scheme	B-Language
's	O
let-syntax	O
and	O
define-syntax	B-Application
macro	O
creation	O
systems	O
are	O
hygienic	O
,	O
so	O
the	O
following	O
Scheme	B-Language
implementation	O
of	O
my-unless	O
will	O
have	O
the	O
desired	O
behavior	O
:	O
</s>
<s>
The	O
hygienic	B-Application
macro	I-Application
processor	O
responsible	O
for	O
transforming	O
the	O
patterns	O
of	O
the	O
input	O
form	O
into	O
an	O
output	O
form	O
detects	O
symbol	O
clashes	O
and	O
resolves	O
them	O
by	O
temporarily	O
changing	O
the	O
names	O
of	O
symbols	O
.	O
</s>
<s>
Macro	O
systems	O
that	O
automatically	O
enforce	O
hygiene	O
originated	O
with	O
Scheme	B-Language
.	O
</s>
<s>
The	O
original	O
KFFD	O
algorithm	O
for	O
a	O
hygienic	B-Application
macro	I-Application
system	O
was	O
presented	O
by	O
Kohlbecker	O
in	O
'	O
86	O
.	O
</s>
<s>
At	O
the	O
time	O
,	O
no	O
standard	O
macro	O
system	O
was	O
adopted	O
by	O
Scheme	B-Language
implementations	O
.	O
</s>
<s>
Shortly	O
thereafter	O
in	O
'	O
87	O
,	O
Kohlbecker	O
and	O
Wand	O
proposed	O
a	O
declarative	O
pattern-based	O
language	O
for	O
writing	O
macros	O
,	O
which	O
was	O
the	O
predecessor	O
to	O
the	O
syntax-rules	B-Application
macro	O
facility	O
adopted	O
by	O
the	O
R5RS	B-Language
standard	O
.	O
</s>
<s>
Syntactic	B-Application
closures	I-Application
,	O
an	O
alternative	O
hygiene	O
mechanism	O
,	O
was	O
proposed	O
as	O
an	O
alternative	O
to	O
Kohlbecker	O
et	O
al	O
.	O
</s>
<s>
Unlike	O
the	O
KFFD	O
algorithm	O
,	O
syntactic	B-Application
closures	I-Application
require	O
the	O
programmer	O
to	O
explicitly	O
specify	O
the	O
resolution	O
of	O
the	O
scope	O
of	O
an	O
identifier	O
.	O
</s>
<s>
introduced	O
the	O
syntax-case	B-Application
macro	O
system	O
,	O
which	O
uses	O
an	O
alternative	O
representation	O
of	O
syntax	O
and	O
maintains	O
hygiene	O
automatically	O
.	O
</s>
<s>
The	O
syntax-case	B-Application
system	O
can	O
express	O
the	O
syntax-rules	B-Application
pattern	O
language	O
as	O
a	O
derived	O
macro	O
.	O
</s>
<s>
The	O
term	O
macro	O
system	O
can	O
be	O
ambiguous	O
because	O
,	O
in	O
the	O
context	O
of	O
Scheme	B-Language
,	O
it	O
can	O
refer	O
to	O
both	O
a	O
pattern-matching	B-Language
construct	O
(	O
e.g.	O
,	O
syntax-rules	B-Application
)	O
and	O
a	O
framework	O
for	O
representing	O
and	O
manipulating	O
syntax	O
(	O
e.g.	O
,	O
syntax-case	B-Application
,	O
syntactic	B-Application
closures	I-Application
)	O
.	O
</s>
<s>
Syntax-rules	B-Application
is	O
a	O
high-level	O
pattern	B-Language
matching	I-Language
facility	O
that	O
attempts	O
to	O
make	O
macros	O
easier	O
to	O
write	O
.	O
</s>
<s>
However	O
,	O
syntax-rules	B-Application
is	O
not	O
able	O
to	O
succinctly	O
describe	O
certain	O
classes	O
of	O
macros	O
and	O
is	O
insufficient	O
to	O
express	O
other	O
macro	O
systems	O
.	O
</s>
<s>
Syntax-rules	B-Application
was	O
described	O
in	O
the	O
R4RS	B-Language
document	O
in	O
an	O
appendix	O
but	O
not	O
mandated	O
.	O
</s>
<s>
Later	O
,	O
R5RS	B-Language
adopted	O
it	O
as	O
a	O
standard	O
macro	O
facility	O
.	O
</s>
<s>
Here	O
is	O
an	O
example	O
syntax-rules	B-Application
macro	O
that	O
swaps	O
the	O
value	O
of	O
two	O
variables	O
:	O
</s>
<s>
Due	O
to	O
the	O
deficiencies	O
of	O
a	O
purely	O
syntax-rules	B-Application
based	O
macro	O
system	O
,	O
the	O
R6RS	O
Scheme	B-Language
standard	O
adopted	O
the	O
syntax-case	B-Application
macro	O
system	O
.	O
</s>
<s>
Unlike	O
syntax-rules	B-Application
,	O
syntax-case	B-Application
contains	O
both	O
a	O
pattern	B-Language
matching	I-Language
language	O
and	O
a	O
low-level	O
facility	O
for	O
writing	O
macros	O
.	O
</s>
<s>
The	O
swap	O
example	O
from	O
before	O
is	O
nearly	O
identical	O
in	O
syntax-case	B-Application
because	O
the	O
pattern	B-Language
matching	I-Language
language	O
is	O
similar	O
:	O
</s>
<s>
However	O
,	O
syntax-case	B-Application
is	O
more	O
powerful	O
than	O
syntax-rules	B-Application
.	O
</s>
<s>
For	O
example	O
,	O
syntax-case	B-Application
macros	O
can	O
specify	O
side-conditions	O
on	O
its	O
pattern	B-Language
matching	I-Language
rules	O
via	O
arbitrary	O
Scheme	B-Language
functions	O
.	O
</s>
<s>
Alternatively	O
,	O
a	O
macro	O
writer	O
can	O
choose	O
not	O
to	O
use	O
the	O
pattern	B-Language
matching	I-Language
frontend	O
and	O
manipulate	O
the	O
syntax	O
directly	O
.	O
</s>
<s>
Using	O
the	O
datum->syntax	O
function	O
,	O
syntax-case	B-Application
macros	O
can	O
also	O
intentionally	O
capture	O
identifiers	O
,	O
thus	O
breaking	O
hygiene	O
.	O
</s>
<s>
Other	O
macro	O
systems	O
have	O
also	O
been	O
proposed	O
and	O
implemented	O
for	O
Scheme	B-Language
.	O
</s>
<s>
Syntactic	B-Application
closures	I-Application
and	O
explicit	O
renaming	O
are	O
two	O
alternative	O
macro	O
systems	O
.	O
</s>
<s>
Both	O
systems	O
are	O
lower-level	O
than	O
syntax-rules	B-Application
and	O
leave	O
the	O
enforcement	O
of	O
hygiene	O
to	O
the	O
macro	O
writer	O
.	O
</s>
<s>
This	O
differs	O
from	O
both	O
syntax-rules	B-Application
and	O
syntax-case	B-Application
,	O
which	O
automatically	O
enforce	O
hygiene	O
by	O
default	O
.	O
</s>
<s>
The	O
swap	O
examples	O
from	O
above	O
are	O
shown	O
here	O
using	O
a	O
syntactic	B-Application
closure	I-Application
and	O
explicit	O
renaming	O
implementation	O
respectively	O
:	O
</s>
<s>
Scheme	B-Language
–	O
syntax-rules	B-Application
,	O
syntax-case	B-Application
,	O
syntactic	B-Application
closures	I-Application
,	O
and	O
others	O
.	O
</s>
<s>
Racket	B-Operating_System
–	O
an	O
offshoot	O
of	O
Scheme	B-Language
.	O
</s>
<s>
Its	O
macro	O
system	O
was	O
originally	O
based	O
on	O
syntax-case	B-Application
,	O
but	O
now	O
has	O
more	O
features	O
.	O
</s>
<s>
Hygienic	B-Application
macros	I-Application
offer	O
safety	O
and	O
referential	O
transparency	O
at	O
the	O
expense	O
of	O
making	O
intentional	O
variable	O
capture	O
less	O
straight-forward	O
.	O
</s>
<s>
Many	O
hygienic	B-Application
macro	I-Application
systems	O
do	O
offer	O
escape	O
hatches	O
without	O
compromising	O
on	O
the	O
guarantees	O
that	O
hygiene	O
provides	O
;	O
for	O
instance	O
,	O
Racket	B-Operating_System
allows	O
you	O
to	O
define	O
,	O
which	O
allow	O
you	O
to	O
selectively	O
introduce	O
bound	O
variables	O
.	O
</s>
