/usr/share/doc/racket/compatibility/defmacro.html is in racket-doc 6.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>1 Legacy macro support</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_0");">▼</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">Compatibility:<span class="mywbr"> </span> Features from Racket Relatives</a></td></tr></table></div><div class="tocviewsublistonly" style="display: block;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1 </td><td><a href="" class="tocviewselflink" data-pltdoc="x">Legacy macro support</a></td></tr><tr><td align="right">2 </td><td><a href="compatibility-package.html" class="tocviewlink" data-pltdoc="x">Limiting Scope:<span class="mywbr"> </span> <span class="RktSym"><span class="RktStxLink">define-<wbr></wbr>package</span></span>, <span class="RktSym"><span class="RktStxLink">open-<wbr></wbr>package</span></span>, ...</a></td></tr><tr><td align="right">3 </td><td><a href="mlists.html" class="tocviewlink" data-pltdoc="x">Mutable List Functions</a></td></tr><tr><td align="right"></td><td><a href="doc-bibliography.html" class="tocviewlink" data-pltdoc="x">Bibliography</a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._define-macro%29%29" class="tocsublink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">define-<wbr></wbr>macro</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._defmacro%29%29" class="tocsublink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">defmacro</span></span></a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="navsettop"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.1", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.1");">top</a></span><span class="navright"> <a href="index.html" title="backward to "Compatibility: Features from Racket Relatives"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "Compatibility: Features from Racket Relatives"" data-pltdoc="x">up</a> <a href="compatibility-package.html" title="forward to "2 Limiting Scope: define-package, open-package, ..."" data-pltdoc="x">next →</a></span> </div><h3 x-source-module="(lib "compatibility/scribblings/compatibility.scrbl")" x-part-tag=""defmacro"">1<tt> </tt><a name="(part._defmacro)"></a><a name="(mod-path._compatibility/defmacro)"></a>Legacy macro support</h3><p><table cellspacing="0" cellpadding="0" class="defmodule"><tr><td align="left" colspan="2"><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=require.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._require%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">require</a></span><span class="stt"> </span><a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">compatibility/defmacro</span></a><span class="RktPn">)</span></td></tr><tr><td align="left"> </td><td align="right"><span class="RpackageSpec"><span class="Smaller"> package:</span> <span class="stt">compatibility-lib</span></span></td></tr></table></p><p>This <a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">compatibility/defmacro</span></a> library provides support for
writing legacy macros. Support for <span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._defmacro%29%29" class="RktStxLink" data-pltdoc="x">defmacro</a></span> is provided
primarily for porting code from other languages (e.g., some
implementations of Scheme or Common Lisp) that use symbol-based
macro systems.</p><p>Use of <span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._defmacro%29%29" class="RktStxLink" data-pltdoc="x">defmacro</a></span> for modern Racket code is <span style="font-weight: bold"><span style="font-style: italic">strongly</span></span>
discouraged. Instead, consider using <span class="RktSym">syntax-parse</span> or
<span class="RktSym">define-simple-macro</span>.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><table cellspacing="0" cellpadding="0" class="together"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._compatibility/defmacro..rkt)._define-macro))"></a><span title="Provided from: compatibility/defmacro | Package: compatibility-lib"><span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._define-macro%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-macro</a></span></span><span class="hspace"> </span><span class="RktVar">id</span><span class="hspace"> </span><span class="RktVar">expr</span><span class="RktPn">)</span></p></blockquote></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._define-macro%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-macro</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">id</span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktVar">formals</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktVar">body</span><span class="hspace"> </span><span class="RktMeta">...+</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="together"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._compatibility/defmacro..rkt)._defmacro))"></a><span title="Provided from: compatibility/defmacro | Package: compatibility-lib"><span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._defmacro%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">defmacro</a></span></span><span class="hspace"> </span><span class="RktVar">id</span><span class="hspace"> </span><span class="RktVar">formals</span><span class="hspace"> </span><span class="RktVar">body</span><span class="hspace"> </span><span class="RktMeta">...+</span><span class="RktPn">)</span></p></blockquote></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="specgrammar"><tr><td align="right" valign="baseline"><span class="RktVar">formals</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktVar">id</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktVar">id</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktVar">id</span><span class="hspace"> </span><span class="RktMeta">...+</span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktVar">id</span><span class="RktPn">)</span></td></tr></table></td></tr></table></td></tr></table></blockquote></div><div class="SIntrapara">Defines a (non-hygienic) macro <span class="RktVar">id</span> through a procedure that
manipulates S-expressions, as opposed to
<a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=syntax-model.html%23%2528tech._syntax._object%2529&version=6.1" class="techoutside Sq" data-pltdoc="x"><span class="techinside">syntax objects</span></a>.</div></p><p>In the first form, <span class="RktVar">expr</span> must produce a procedure. In the
second form, <span class="RktVar">formals</span> determines the formal arguments of the
procedure, as in <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=lambda.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._lambda%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">lambda</a></span>, and the <span class="RktVar">expr</span>s are the
procedure body. The last form, with <span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._defmacro%29%29" class="RktStxLink" data-pltdoc="x">defmacro</a></span>, is like the
second form, but with slightly different parentheses.</p><p>In all cases, the procedure is generated in the
<a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=syntax-model.html%23%2528tech._transformer._environment%2529&version=6.1" class="techoutside Sq" data-pltdoc="x"><span class="techinside">transformer environment</span></a>, not the normal environment.</p><p>In a use of the macro,</p><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktVar">id</span><span class="hspace"> </span><span class="RktSym">datum</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span></p></blockquote><p><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stxops.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._syntax-%7E3edatum%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">syntax->datum</a></span> is applied to the expression, and the
transformer procedure is applied to the <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cdr%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">cdr</a></span> of the resulting
list. If the number of <span class="RktSym">datum</span>s does not match the procedure’s
arity, or if <span class="RktVar">id</span> is used in a context that does not match the
above pattern, then a syntax error is reported.</p><p>After the macro procedure returns, the result is compared to the
procedure’s arguments. For each value that appears exactly once within
the arguments (or, more precisely, within the S-expression derived
from the original source syntax), if the same value appears in the
result, it is replaced with a syntax object from the original
expression. This heuristic substitution preserves source location
information in many cases, despite the macro procedure’s operation on
raw S-expressions.</p><p>After substituting syntax objects for preserved values, the entire
macro result is converted to syntax with <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stxops.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._datum-%7E3esyntax%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">datum->syntax</a></span>. The
original expression supplies the lexical context and source location
for converted elements.</p><p><span style="font-weight: bold">Important:</span> Although <span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._define-macro%29%29" class="RktStxLink" data-pltdoc="x">define-macro</a></span> is non-hygienic, it
is still restricted by Racket’s phase separation rules. This
means that a macro cannot access run-time bindings, because it is
executed in the syntax-expansion phase. Translating code that
involves <span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._define-macro%29%29" class="RktStxLink" data-pltdoc="x">define-macro</a></span> or <span class="RktSym"><a href="#%28form._%28%28lib._compatibility%2Fdefmacro..rkt%29._defmacro%29%29" class="RktStxLink" data-pltdoc="x">defmacro</a></span> from an
implementation without this restriction usually implies separating
macro related functionality into a <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=begin.html%23%2528form._%2528%2528quote._%7E23%7E25kernel%2529._begin-for-syntax%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">begin-for-syntax</a></span> or a
module (that will be imported with <span class="RktSym">require-for-syntax</span>) and
properly distinguishing syntactic information from run-time
information.</p><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.1", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.1");">top</a></span><span class="navright"> <a href="index.html" title="backward to "Compatibility: Features from Racket Relatives"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "Compatibility: Features from Racket Relatives"" data-pltdoc="x">up</a> <a href="compatibility-package.html" title="forward to "2 Limiting Scope: define-package, open-package, ..."" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html>
|