<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Random Hacks: Why Hygienic Macros Rock</title>
    <link>http://www.randomhacks.net/articles/2002/09/13/hygienic-macros</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Technology and Other Fun Stuff</description>
    <item>
      <title>"Why Hygienic Macros Rock" by Scott</title>
      <description>&lt;p&gt;Daniel: Ok, thanks.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m acquainted with Forth. I read both &lt;em&gt;Starting Forth&lt;/em&gt; and &lt;em&gt;Thinking Forth&lt;/em&gt; a few days after posting the above comment, actually; I love the concatenative approach, though I find Forth a bit too low-level for my taste. (My favorite language is currently OCaml, so you can guess how I feel about working without any type system whatsover.) I&amp;#8217;ve also looked a little at Factor, but not in depth.&lt;/p&gt;


	&lt;p&gt;That said, the source to a Forth interpreter in i386 assembly and Forth was one of the single most mind-blowing programming things I&amp;#8217;ve ever read. When I saw that the interpreter had a bit for whether the code was being compiled or evaluated, and immediate functions could toggle it at runtime, everything suddenly made sense. So much flexibility emerging from so few constructs!&lt;/p&gt;


	&lt;p&gt;http://www.annexia.org/_file/jonesforth.s.txt&lt;/p&gt;</description>
      <pubDate>Tue, 15 Jul 2008 22:30:03 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:5306f8c6-4510-4d49-aa1f-5c2ea96606bc</guid>
      <link>http://www.randomhacks.net/articles/2002/09/13/hygienic-macros#comment-578</link>
    </item>
    <item>
      <title>"Why Hygienic Macros Rock" by Daniel</title>
      <description>&lt;p&gt;I have actually read a lot about hygienic vs non-hygienic macros. I just cannot recall what blogs and sites I read them.&lt;/p&gt;


	&lt;p&gt;You might try smuglispweeny and lambda-the-ultimate blogs, though. And wikipedia.&lt;/p&gt;


	&lt;p&gt;The thing is, gensyms handles some of the stuff hygienic macros handle, but not all of the stuff. There are some complex cases which would require heroic efforts in &lt;span class="caps"&gt;LISP&lt;/span&gt;, and very prone to errors at that.&lt;/p&gt;


	&lt;p&gt;On the other hand, hygienic macros can access the runtime context, in a more verbose way.&lt;/p&gt;


	&lt;p&gt;So, really, they each can be used for the same things, with varied levels of complexity depending on the task. But let me advocate hygienic macros a bit here.&lt;/p&gt;


	&lt;p&gt;There once was a language called Forth. Forth was interesting in that not only it was written in itself, but all the internals were available to any programs written in it, and, furthermore, it could be changed at will. You could change the parser, for instance, or you could change how it performed compilation.&lt;/p&gt;


	&lt;p&gt;Needless to say, it was powerful in the way such languages are. The thing is&amp;#8230; Forth lacked abstraction. Yes, you could change the compiler. But, of course, you&amp;#8217;d have to know how the specific compiler you were changing worked&amp;#8212;and I don&amp;#8217;t mean simply dialect differences. The most famous Forth generated indirectly threaded code, quite a few generated directly threaded code, some generated subrouting threaded code, others generated bytecode, and others compiled directly to machine code.&lt;/p&gt;


	&lt;p&gt;So it was very powerful stuff, which had very little portability. Well, let&amp;#8217;s be honest. It had no portability at all.&lt;/p&gt;


	&lt;p&gt;And here is the thing with non-hygienic macros&amp;#8230; the programmers using someone&amp;#8217;s macro also have to know how that macro works. Either that, or you add stuff to your macro until it is, effectively, hygienic.&lt;/p&gt;


	&lt;p&gt;So, by using hygienic macros, you guarantee a level of portability to them similar to library functions.&lt;/p&gt;</description>
      <pubDate>Sun, 22 Jun 2008 21:47:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:569edc73-4167-4cba-bbfa-ef2b1225b0cd</guid>
      <link>http://www.randomhacks.net/articles/2002/09/13/hygienic-macros#comment-577</link>
    </item>
    <item>
      <title>"Why Hygienic Macros Rock" by Eric</title>
      <description>&lt;p&gt;Scott: That&amp;#8217;s a good question, and I don&amp;#8217;t actually know the answer.&lt;/p&gt;


	&lt;p&gt;Most Scheme implementations take a distantly-related approach. They generally have two different hygenic macro systems:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;A &amp;#8220;low-level&amp;#8221; macro system, which works roughly like &lt;span class="caps"&gt;LISP&lt;/span&gt;, but which provides hygiene by default, but also provides the ability to violate hygiene selectively. This tends to be a bit fiddly to use.&lt;/li&gt;
		&lt;li&gt;A &amp;#8220;high-level&amp;#8221; macro system, which is based on hygienic rewrite rules. This is very easy to use, and will work for nearly all common macros.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Of course, using the low-level macro system, you can easily implement Lisp-style non-hygienic macros.&lt;/p&gt;


	&lt;p&gt;The &lt;span class="caps"&gt;PLT&lt;/span&gt; people have recently added another very slick feature to the standard Scheme toolkit: The ability the selectively violate hygiene from inside rewrite rules, in a &lt;a href="http://blog.plt-scheme.org/2008/02/dirty-looking-hygiene.html" rel="nofollow"&gt;carefully controlled&lt;/a&gt; fashion. This is a really nice feature, and we&amp;#8217;ve been using it at work with great success.&lt;/p&gt;</description>
      <pubDate>Fri, 20 Jun 2008 07:40:30 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:1053b2b2-1a16-4305-a516-c8dd0265bd4c</guid>
      <link>http://www.randomhacks.net/articles/2002/09/13/hygienic-macros#comment-576</link>
    </item>
    <item>
      <title>"Why Hygienic Macros Rock" by Scott</title>
      <description>&lt;p&gt;To what extent can hygienic macros be implemented in non- and vice versa? I&amp;#8217;m more familiar with Emacs Lisp-style macros than CL or Scheme macros, but it seems like the hygiene involves automatically writing code with gensyms to avoid variable capture and other compile-time analysis. If one is implemented in terms of the other, it would probably make the most sense to have two different forms, e.g. hmacro for declaring hygienic macros, and macro for when you deliberately want to do things like variable capture.&lt;/p&gt;</description>
      <pubDate>Thu, 19 Jun 2008 20:15:42 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:3d805087-bf74-43a9-aa42-addf5622bbeb</guid>
      <link>http://www.randomhacks.net/articles/2002/09/13/hygienic-macros#comment-575</link>
    </item>
    <item>
      <title>Why Hygienic Macros Rock</title>
      <description>    &lt;p&gt;I've recently been reading a lot of &lt;a href='http://www.paulgraham.com/articles.html'&gt;excellent essays on
    programming language design&lt;/a&gt; by Paul Graham.  Paul and I agree about
    a number of things: (1) LISP is beautiful and powerful family of
    languages, even by modern standards, (2) all existing dialects of LISP
    are lacking a certain something, and (3) programmatic macros are a Good
    Idea.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.randomhacks.net/articles/2002/09/13/hygienic-macros"&gt;Read More&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 13 Sep 2002 00:00:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:213d6f83-48bd-4661-a3eb-98fb3784f7da</guid>
      <author>Eric</author>
      <link>http://www.randomhacks.net/articles/2002/09/13/hygienic-macros</link>
      <category>Macros</category>
      <category>LISP</category>
      <category>Hacks</category>
      <category>Recommended</category>
      <trackback:ping>http://www.randomhacks.net/articles/trackback/24</trackback:ping>
    </item>
  </channel>
</rss>
