Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Site updated at 2012-04-28 09:09:41 UTC

  • Loading branch information...
commit 77a30e0f6a08d44ff5ee75173454fb88c8fa4407 1 parent c71c17e
Tomohiro Matsuyama authored
View
79 atom.xml
@@ -4,7 +4,7 @@
<title><![CDATA[Random Notes]]></title>
<link href="http://m2ym.github.com/atom.xml" rel="self"/>
<link href="http://m2ym.github.com/"/>
- <updated>2012-04-21T23:23:54+09:00</updated>
+ <updated>2012-04-28T18:07:54+09:00</updated>
<id>http://m2ym.github.com/</id>
<author>
<name><![CDATA[m2ym]]></name>
@@ -14,6 +14,83 @@
<entry>
+ <title type="html"><![CDATA[マクロ内でevalするべきでない理由]]></title>
+ <link href="http://m2ym.github.com/blog/2012/04/28/eval-in-macros/"/>
+ <updated>2012-04-28T17:00:00+09:00</updated>
+ <id>http://m2ym.github.com/blog/2012/04/28/eval-in-macros</id>
+ <content type="html"><![CDATA[<p>答え:レキシカル環境が無視されるから。</p>
+
+<p>実例で解説しよう。<a href="http://www.pps.jussieu.fr/~jch/software/cl-yacc/">CL-Yacc</a>というライブラリがある。名前の通りyaccをCommon Lispにポートしたものだ。実装は単純明快で、背景となる理論を知っていればすんなり読めるはずだ。</p>
+
+<p>CL-Yaccは<code>define-parser</code>というマクロを提供しており、ユーザーはこれを用いてパーサーを定義する。以下に簡単な四則演算パーサーの例を示す。</p>
+
+<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+<span class='line-number'>2</span>
+<span class='line-number'>3</span>
+<span class='line-number'>4</span>
+<span class='line-number'>5</span>
+<span class='line-number'>6</span>
+<span class='line-number'>7</span>
+<span class='line-number'>8</span>
+<span class='line-number'>9</span>
+<span class='line-number'>10</span>
+</pre></td><td class='code'><pre><code class='common-lisp'><span class='line'><span class="p">(</span><span class="nv">yacc:define-parser</span> <span class="vg">*parser*</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:start-symbol</span> <span class="nv">expression</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:terminals</span> <span class="p">(</span><span class="nc">integer</span> <span class="nb">+</span> <span class="nb">-</span> <span class="nb">*</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">+</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">+</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">-</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">-</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">*</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">*</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">/</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">/</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="nc">integer</span><span class="p">))</span>
+</span></code></pre></td></tr></table></div></figure>
+
+
+<p>セマンティックアクションがすべて類似していることに気付くだろう。試しに<code>macrolet</code>を使って以下のように書きかえてみる。</p>
+
+<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+<span class='line-number'>2</span>
+<span class='line-number'>3</span>
+<span class='line-number'>4</span>
+<span class='line-number'>5</span>
+<span class='line-number'>6</span>
+<span class='line-number'>7</span>
+<span class='line-number'>8</span>
+<span class='line-number'>9</span>
+<span class='line-number'>10</span>
+<span class='line-number'>11</span>
+<span class='line-number'>12</span>
+<span class='line-number'>13</span>
+<span class='line-number'>14</span>
+</pre></td><td class='code'><pre><code class='common-lisp'><span class='line'><span class="p">(</span><span class="k">macrolet</span> <span class="p">((</span><span class="nv">app</span> <span class="p">(</span><span class="nv">op</span><span class="p">)</span>
+</span><span class='line'> <span class="o">`</span><span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="o">,</span><span class="nv">op</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">))))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">yacc:define-parser</span> <span class="vg">*parser*</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:start-symbol</span> <span class="nv">expression</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:terminals</span> <span class="p">(</span><span class="nc">integer</span> <span class="nb">+</span> <span class="nb">-</span> <span class="nb">*</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">+</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">+</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">-</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">-</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">*</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">*</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">/</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'> <span class="nc">integer</span><span class="p">)))</span>
+</span></code></pre></td></tr></table></div></figure>
+
+
+<p>ネストは深くなったが、パーサー定義はより簡潔になったはずだ。しかし、この新しい定義を評価(コンパイル)すると<code>The function APP is undefined.</code>というエラーが発生する。なぜか。</p>
+
+<p>CL-Yaccは<strong>マクロ展開時</strong>にパーサーテーブルを生成する。そのとき、セマンティックアクションも関数形式に変換して同テーブルに格納する。このような手順をとる場合、セマンティックアクションとして<code>define-parser</code>に記述されたフォーム(先の例では<code>(lambda (a _ b) ...)</code>)は<code>eval</code>で評価せざるを得ない。</p>
+
+<p><code>eval</code>に渡されたフォームは空レキシカル環境、つまりグローバル環境上で評価される。空レキシカル環境上で評価されるということは、<code>symbol-macrolet</code>や<code>macrolet</code>などのレキシカル環境に作用するオペレータが全く無効になるということである(たとえ字句的に包含していようが)。したがって、上記の<code>APP</code>は見えなかったというわけである。</p>
+
+<p>この問題は全くもってLispの力を制限するものであるから、本当に必要なときを除いて、特にマクロ展開中は、<code>eval</code>は使わないようにすべきである。</p>
+]]></content>
+ </entry>
+
+ <entry>
<title type="html"><![CDATA[初投稿]]></title>
<link href="http://m2ym.github.com/blog/2012/04/21/first-post/"/>
<updated>2012-04-21T23:09:00+09:00</updated>
View
6 blog/2012/04/21/first-post/index.html
@@ -166,6 +166,8 @@ <h1 class="entry-title">初投稿</h1>
<p class="meta">
+ <a class="basic-alignment right" href="/blog/2012/04/28/eval-in-macros/" title="Next Post: マクロ内でevalするべきでない理由">マクロ内でevalするべきでない理由 &raquo;</a>
+
</p>
</footer>
</article>
@@ -185,6 +187,10 @@ <h1 class="entry-title">初投稿</h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/2012/04/28/eval-in-macros/">マクロ内でevalするべきでない理由</a>
+ </li>
+
+ <li class="post">
<a href="/blog/2012/04/21/first-post/">初投稿</a>
</li>
View
342 blog/2012/04/28/eval-in-macros/index.html
@@ -0,0 +1,342 @@
+
+<!DOCTYPE html>
+<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
+<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
+<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
+<head>
+ <meta charset="utf-8">
+ <title>マクロ内でevalするべきでない理由 - Random Notes</title>
+ <meta name="author" content="m2ym">
+
+
+ <meta name="description" content="答え:レキシカル環境が無視されるから。 実例で解説しよう。CL-Yaccというライブラリがある。名前の通りyaccをCommon Lispにポートしたものだ。実装は単純明快で、背景となる理論を知っていればすんなり読めるはずだ。 CL-Yaccはdefine-parserというマクロを提供しており、 &hellip;">
+
+
+ <!-- http://t.co/dKP3o1e -->
+ <meta name="HandheldFriendly" content="True">
+ <meta name="MobileOptimized" content="320">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+
+
+ <link rel="canonical" href="http://m2ym.github.com/blog/2012/04/28/eval-in-macros">
+ <link href="/favicon.png" rel="icon">
+ <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
+ <script src="/javascripts/modernizr-2.0.js"></script>
+ <script src="/javascripts/ender.js"></script>
+ <script src="/javascripts/octopress.js" type="text/javascript"></script>
+ <link href="/atom.xml" rel="alternate" title="Random Notes" type="application/atom+xml">
+ <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
+<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+
+
+
+</head>
+
+<body >
+ <header role="banner"><hgroup>
+ <h1><a href="/">Random Notes</a></h1>
+
+ <h2>Lisp, Haskell, OCaml, etc</h2>
+
+</hgroup>
+
+</header>
+ <nav role="navigation"><ul class="subscription" data-subscription="rss">
+ <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
+
+</ul>
+
+<form action="http://google.com/search" method="get">
+ <fieldset role="search">
+ <input type="hidden" name="q" value="site:m2ym.github.com" />
+ <input class="search" type="text" name="q" results="0" placeholder="Search"/>
+ </fieldset>
+</form>
+
+<ul class="main-navigation">
+ <li><a href="/">Blog</a></li>
+ <li><a href="/blog/archives">Archives</a></li>
+</ul>
+
+</nav>
+ <div id="main">
+ <div id="content">
+ <div>
+<article class="hentry" role="article">
+
+ <header>
+
+ <h1 class="entry-title">マクロ内でevalするべきでない理由</h1>
+
+
+ <p class="meta">
+
+
+
+
+
+
+
+
+
+
+
+
+<time datetime="2012-04-28T17:00:00+09:00" pubdate data-updated="true">Apr 28<span>th</span>, 2012</time>
+
+ | <a href="#disqus_thread">Comments</a>
+
+ </p>
+
+ </header>
+
+
+<div class="entry-content"><p>答え:レキシカル環境が無視されるから。</p>
+
+<p>実例で解説しよう。<a href="http://www.pps.jussieu.fr/~jch/software/cl-yacc/">CL-Yacc</a>というライブラリがある。名前の通りyaccをCommon Lispにポートしたものだ。実装は単純明快で、背景となる理論を知っていればすんなり読めるはずだ。</p>
+
+<p>CL-Yaccは<code>define-parser</code>というマクロを提供しており、ユーザーはこれを用いてパーサーを定義する。以下に簡単な四則演算パーサーの例を示す。</p>
+
+<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+<span class='line-number'>2</span>
+<span class='line-number'>3</span>
+<span class='line-number'>4</span>
+<span class='line-number'>5</span>
+<span class='line-number'>6</span>
+<span class='line-number'>7</span>
+<span class='line-number'>8</span>
+<span class='line-number'>9</span>
+<span class='line-number'>10</span>
+</pre></td><td class='code'><pre><code class='common-lisp'><span class='line'><span class="p">(</span><span class="nv">yacc:define-parser</span> <span class="vg">*parser*</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:start-symbol</span> <span class="nv">expression</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:terminals</span> <span class="p">(</span><span class="nc">integer</span> <span class="nb">+</span> <span class="nb">-</span> <span class="nb">*</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">+</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">+</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">-</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">-</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">*</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">*</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">/</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">/</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="nc">integer</span><span class="p">))</span>
+</span></code></pre></td></tr></table></div></figure>
+
+
+<p>セマンティックアクションがすべて類似していることに気付くだろう。試しに<code>macrolet</code>を使って以下のように書きかえてみる。</p>
+
+<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+<span class='line-number'>2</span>
+<span class='line-number'>3</span>
+<span class='line-number'>4</span>
+<span class='line-number'>5</span>
+<span class='line-number'>6</span>
+<span class='line-number'>7</span>
+<span class='line-number'>8</span>
+<span class='line-number'>9</span>
+<span class='line-number'>10</span>
+<span class='line-number'>11</span>
+<span class='line-number'>12</span>
+<span class='line-number'>13</span>
+<span class='line-number'>14</span>
+</pre></td><td class='code'><pre><code class='common-lisp'><span class='line'><span class="p">(</span><span class="k">macrolet</span> <span class="p">((</span><span class="nv">app</span> <span class="p">(</span><span class="nv">op</span><span class="p">)</span>
+</span><span class='line'> <span class="o">`</span><span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="o">,</span><span class="nv">op</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">))))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">yacc:define-parser</span> <span class="vg">*parser*</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:start-symbol</span> <span class="nv">expression</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:terminals</span> <span class="p">(</span><span class="nc">integer</span> <span class="nb">+</span> <span class="nb">-</span> <span class="nb">*</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">+</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">+</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">-</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">-</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">*</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">*</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">/</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'> <span class="nc">integer</span><span class="p">)))</span>
+</span></code></pre></td></tr></table></div></figure>
+
+
+<p>ネストは深くなったが、パーサー定義はより簡潔になったはずだ。しかし、この新しい定義を評価(コンパイル)すると<code>The function APP is undefined.</code>というエラーが発生する。なぜか。</p>
+
+<p>CL-Yaccは<strong>マクロ展開時</strong>にパーサーテーブルを生成する。そのとき、セマンティックアクションも関数形式に変換して同テーブルに格納する。このような手順をとる場合、セマンティックアクションとして<code>define-parser</code>に記述されたフォーム(先の例では<code>(lambda (a _ b) ...)</code>)は<code>eval</code>で評価せざるを得ない。</p>
+
+<p><code>eval</code>に渡されたフォームは空レキシカル環境、つまりグローバル環境上で評価される。空レキシカル環境上で評価されるということは、<code>symbol-macrolet</code>や<code>macrolet</code>などのレキシカル環境に作用するオペレータが全く無効になるということである(たとえ字句的に包含していようが)。したがって、上記の<code>APP</code>は見えなかったというわけである。</p>
+
+<p>この問題は全くもってLispの力を制限するものであるから、本当に必要なときを除いて、特にマクロ展開中は、<code>eval</code>は使わないようにすべきである。</p>
+</div>
+
+
+ <footer>
+ <p class="meta">
+
+
+
+<span class="byline author vcard">Posted by <span class="fn">m2ym</span></span>
+
+
+
+
+
+
+
+
+
+
+
+
+
+<time datetime="2012-04-28T17:00:00+09:00" pubdate data-updated="true">Apr 28<span>th</span>, 2012</time>
+
+
+<span class="categories">
+
+ <a class='category' href='/blog/categories/lisp/'>Lisp</a>
+
+</span>
+
+
+ </p>
+
+ <div class="sharing">
+
+ <a href="http://twitter.com/share" class="twitter-share-button" data-url="http://m2ym.github.com/blog/2012/04/28/eval-in-macros/" data-via="m2ym" data-counturl="http://m2ym.github.com/blog/2012/04/28/eval-in-macros/" >Tweet</a>
+
+
+
+</div>
+
+
+ <p class="meta">
+
+ <a class="basic-alignment left" href="/blog/2012/04/21/first-post/" title="Previous Post: 初投稿">&laquo; 初投稿</a>
+
+
+ </p>
+ </footer>
+</article>
+
+ <section>
+ <h1>Comments</h1>
+ <div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+</div>
+ </section>
+
+</div>
+
+<aside class="sidebar">
+
+ <section>
+ <h1>Recent Posts</h1>
+ <ul id="recent_posts">
+
+ <li class="post">
+ <a href="/blog/2012/04/28/eval-in-macros/">マクロ内でevalするべきでない理由</a>
+ </li>
+
+ <li class="post">
+ <a href="/blog/2012/04/21/first-post/">初投稿</a>
+ </li>
+
+ </ul>
+</section>
+
+<section>
+ <h1>GitHub Repos</h1>
+ <ul id="gh_repos">
+ <li class="loading">Status updating...</li>
+ </ul>
+
+ <a href="https://github.com/m2ym">@m2ym</a> on GitHub
+
+ <script type="text/javascript">
+ $.domReady(function(){
+ if (!window.jXHR){
+ var jxhr = document.createElement('script');
+ jxhr.type = 'text/javascript';
+ jxhr.src = '/javascripts/libs/jXHR.js';
+ var s = document.getElementsByTagName('script')[0];
+ s.parentNode.insertBefore(jxhr, s);
+ }
+
+ github.showRepos({
+ user: 'm2ym',
+ count: 5,
+ skip_forks: true,
+ target: '#gh_repos'
+ });
+ });
+ </script>
+ <script src="/javascripts/github.js" type="text/javascript"> </script>
+</section>
+
+
+<section>
+ <h1>Latest Tweets</h1>
+ <ul id="tweets">
+ <li class="loading">Status updating...</li>
+ </ul>
+ <script type="text/javascript">
+ $.domReady(function(){
+ getTwitterFeed("m2ym", 4, false);
+ });
+ </script>
+ <script src="/javascripts/twitter.js" type="text/javascript"> </script>
+
+ <a href="http://twitter.com/m2ym" class="twitter-follow-button" data-show-count="false">Follow @m2ym</a>
+
+</section>
+
+
+
+
+
+
+</aside>
+
+
+ </div>
+ </div>
+ <footer role="contentinfo"><p>
+ Copyright &copy; 2012 - m2ym -
+ <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
+</p>
+
+</footer>
+
+
+<script type="text/javascript">
+ var disqus_shortname = 'm2ym-blog';
+
+
+ // var disqus_developer = 1;
+ var disqus_identifier = 'http://m2ym.github.com/blog/2012/04/28/eval-in-macros/';
+ var disqus_url = 'http://m2ym.github.com/blog/2012/04/28/eval-in-macros/';
+ var disqus_script = 'embed.js';
+
+ (function () {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ }());
+</script>
+
+
+
+
+
+
+
+ <script type="text/javascript">
+ (function(){
+ var twitterWidgets = document.createElement('script');
+ twitterWidgets.type = 'text/javascript';
+ twitterWidgets.async = true;
+ twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
+ document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
+ })();
+ </script>
+
+
+
+
+
+</body>
+</html>
View
23 blog/archives/index.html
@@ -9,8 +9,9 @@
<meta name="author" content="m2ym">
- <meta name="description" content="Blog Archive 2012 初投稿
-Apr 21 2012 Recent Posts 初投稿 GitHub Repos Status updating... @m2ym on GitHub $.domReady(function(){ if (!window.jXHR){ var &hellip;">
+ <meta name="description" content="Blog Archive 2012 マクロ内でevalするべきでない理由
+Apr 28 2012 posted in Lisp 初投稿
+Apr 21 2012 Recent Posts マクロ内でevalするべきでない理由 初投稿 GitHub Repos Status updating &hellip;">
<!-- http://t.co/dKP3o1e -->
@@ -80,6 +81,20 @@ <h1 class="entry-title">Blog Archive</h1>
<article>
+<h1><a href="/blog/2012/04/28/eval-in-macros/">マクロ内でevalするべきでない理由</a></h1>
+<time datetime="2012-04-28T17:00:00+09:00" pubdate><span class='month'>Apr</span> <span class='day'>28</span> <span class='year'>2012</span></time>
+
+<footer>
+ <span class="categories">posted in <a class='category' href='/blog/categories/lisp/'>Lisp</a></span>
+</footer>
+
+
+</article>
+
+
+
+<article>
+
<h1><a href="/blog/2012/04/21/first-post/">初投稿</a></h1>
<time datetime="2012-04-21T23:09:00+09:00" pubdate><span class='month'>Apr</span> <span class='day'>21</span> <span class='year'>2012</span></time>
@@ -100,6 +115,10 @@ <h1 class="entry-title">Blog Archive</h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/2012/04/28/eval-in-macros/">マクロ内でevalするべきでない理由</a>
+ </li>
+
+ <li class="post">
<a href="/blog/2012/04/21/first-post/">初投稿</a>
</li>
View
75 blog/categories/lisp/atom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+ <title><![CDATA[Category: Lisp | Random Notes]]></title>
+ <link href="http://m2ym.github.com/blog/categories/lisp/atom.xml" rel="self"/>
+ <link href="http://m2ym.github.com/"/>
+ <updated>2012-04-28T18:07:54+09:00</updated>
+ <id>http://m2ym.github.com/</id>
+ <author>
+ <name><![CDATA[m2ym]]></name>
+
+ </author>
+ <generator uri="http://octopress.org/">Octopress</generator>
+
+
+ <entry>
+ <title type="html"><![CDATA[マクロ内でevalするべきでない理由]]></title>
+ <link href="http://m2ym.github.com/blog/2012/04/28/eval-in-macros/"/>
+ <updated>2012-04-28T17:00:00+09:00</updated>
+ <id>http://m2ym.github.com/blog/2012/04/28/eval-in-macros</id>
+ <content type="html"><![CDATA[<p>答え:レキシカル環境が無視されるから。</p>
+
+<p>実例で解説しよう。<a href="http://www.pps.jussieu.fr/~jch/software/cl-yacc/">CL-Yacc</a>というライブラリがある。名前の通りyaccをCommon Lispにポートしたものだ。実装は単純明快で、背景となる理論を知っていればすんなり読めるはずだ。</p>
+
+<p>CL-Yaccは<code>define-parser</code>というマクロを提供しており、ユーザーはこれを用いてパーサーを定義する。以下に簡単な四則演算パーサーの例を示す。</p>
+
+<p>```common-lisp
+(yacc:define-parser <em>parser</em>
+ (:start-symbol expression)
+ (:terminals (integer + - * /))</p>
+
+<p> (expression
+ (expression + expression (lambda (a _ b) (declare (ignore <em>)) (+ a b)))
+ (expression - expression (lambda (a _ b) (declare (ignore </em>)) (- a b)))
+ (expression * expression (lambda (a _ b) (declare (ignore <em>)) (* a b)))
+ (expression / expression (lambda (a _ b) (declare (ignore </em>)) (/ a b)))
+ integer))
+```</p>
+
+<p>セマンティックアクションがすべて類似していることに気付くだろう。試しに<code>macrolet</code>を使って以下のように書きかえてみる。</p>
+
+<p>```common-lisp
+(macrolet ((app (op)</p>
+
+<pre><code> `(lambda (a _ b)
+ (declare (ignore _))
+ (,op a b))))
+</code></pre>
+
+<p> (yacc:define-parser <em>parser</em></p>
+
+<pre><code>(:start-symbol expression)
+(:terminals (integer + - * /))
+
+(expression
+ (expression + expression (app +))
+ (expression - expression (app -))
+ (expression * expression (app *))
+ (expression / expression (app /))
+ integer)))
+</code></pre>
+
+<p>```</p>
+
+<p>ネストは深くなったが、パーサー定義はより簡潔になったはずだ。しかし、この新しい定義を評価(コンパイル)すると<code>The function APP is undefined.</code>というエラーが発生する。なぜか。</p>
+
+<p>CL-Yaccは<strong>マクロ展開時</strong>にパーサーテーブルを生成する。そのとき、セマンティックアクションも関数形式に変換して同テーブルに格納する。このような手順をとる場合、セマンティックアクションとして<code>define-parser</code>に記述されたフォーム(先の例では<code>(lambda (a _ b) ...)</code>)は<code>eval</code>で評価せざるを得ない。</p>
+
+<p><code>eval</code>に渡されたフォームは空レキシカル環境、つまりグローバル環境上で評価される。空レキシカル環境上で評価されるということは、<code>symbol-macrolet</code>や<code>macrolet</code>などのレキシカル環境に作用するオペレータが全く無効になるということである(たとえ字句的に包含していようが)。したがって、上記の<code>APP</code>は見えなかったというわけである。</p>
+
+<p>この問題は全くもってLispの力を制限するものであるから、本当に必要なときを除いて、特にマクロ展開中は、<code>eval</code>は使わないようにすべきである。</p>
+]]></content>
+ </entry>
+
+</feed>
View
214 blog/categories/lisp/index.html
@@ -0,0 +1,214 @@
+
+<!DOCTYPE html>
+<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
+<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
+<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
+<head>
+ <meta charset="utf-8">
+ <title>Category: Lisp - Random Notes</title>
+ <meta name="author" content="m2ym">
+
+
+ <meta name="description" content="Category: Lisp">
+
+
+ <!-- http://t.co/dKP3o1e -->
+ <meta name="HandheldFriendly" content="True">
+ <meta name="MobileOptimized" content="320">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+
+
+ <link rel="canonical" href="http://m2ym.github.comblog/categories/lisp">
+ <link href="/favicon.png" rel="icon">
+ <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
+ <script src="/javascripts/modernizr-2.0.js"></script>
+ <script src="/javascripts/ender.js"></script>
+ <script src="/javascripts/octopress.js" type="text/javascript"></script>
+ <link href="/atom.xml" rel="alternate" title="Random Notes" type="application/atom+xml">
+ <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
+<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+
+
+
+</head>
+
+<body >
+ <header role="banner"><hgroup>
+ <h1><a href="/">Random Notes</a></h1>
+
+ <h2>Lisp, Haskell, OCaml, etc</h2>
+
+</hgroup>
+
+</header>
+ <nav role="navigation"><ul class="subscription" data-subscription="rss">
+ <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
+
+</ul>
+
+<form action="http://google.com/search" method="get">
+ <fieldset role="search">
+ <input type="hidden" name="q" value="site:m2ym.github.com" />
+ <input class="search" type="text" name="q" results="0" placeholder="Search"/>
+ </fieldset>
+</form>
+
+<ul class="main-navigation">
+ <li><a href="/">Blog</a></li>
+ <li><a href="/blog/archives">Archives</a></li>
+</ul>
+
+</nav>
+ <div id="main">
+ <div id="content">
+ <div>
+<article role="article">
+
+ <header>
+ <h1 class="entry-title">Category: Lisp</h1>
+
+ </header>
+
+ <div id="blog-archives" class="category">
+
+
+
+
+ <h2>2012</h2>
+
+<article>
+
+<h1><a href="/blog/2012/04/28/eval-in-macros/">マクロ内でevalするべきでない理由</a></h1>
+<time datetime="2012-04-28T17:00:00+09:00" pubdate><span class='month'>Apr</span> <span class='day'>28</span> <span class='year'>2012</span></time>
+
+<footer>
+ <span class="categories">posted in <a class='category' href='/blog/categories/lisp/'>Lisp</a></span>
+</footer>
+
+
+</article>
+
+</div>
+
+
+</article>
+
+</div>
+
+<aside class="sidebar">
+
+ <section>
+ <h1>Recent Posts</h1>
+ <ul id="recent_posts">
+
+ <li class="post">
+ <a href="/blog/2012/04/28/eval-in-macros/">マクロ内でevalするべきでない理由</a>
+ </li>
+
+ <li class="post">
+ <a href="/blog/2012/04/21/first-post/">初投稿</a>
+ </li>
+
+ </ul>
+</section>
+
+<section>
+ <h1>GitHub Repos</h1>
+ <ul id="gh_repos">
+ <li class="loading">Status updating...</li>
+ </ul>
+
+ <a href="https://github.com/m2ym">@m2ym</a> on GitHub
+
+ <script type="text/javascript">
+ $.domReady(function(){
+ if (!window.jXHR){
+ var jxhr = document.createElement('script');
+ jxhr.type = 'text/javascript';
+ jxhr.src = '/javascripts/libs/jXHR.js';
+ var s = document.getElementsByTagName('script')[0];
+ s.parentNode.insertBefore(jxhr, s);
+ }
+
+ github.showRepos({
+ user: 'm2ym',
+ count: 5,
+ skip_forks: true,
+ target: '#gh_repos'
+ });
+ });
+ </script>
+ <script src="/javascripts/github.js" type="text/javascript"> </script>
+</section>
+
+
+<section>
+ <h1>Latest Tweets</h1>
+ <ul id="tweets">
+ <li class="loading">Status updating...</li>
+ </ul>
+ <script type="text/javascript">
+ $.domReady(function(){
+ getTwitterFeed("m2ym", 4, false);
+ });
+ </script>
+ <script src="/javascripts/twitter.js" type="text/javascript"> </script>
+
+ <a href="http://twitter.com/m2ym" class="twitter-follow-button" data-show-count="false">Follow @m2ym</a>
+
+</section>
+
+
+
+
+
+
+</aside>
+
+
+ </div>
+ </div>
+ <footer role="contentinfo"><p>
+ Copyright &copy; 2012 - m2ym -
+ <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
+</p>
+
+</footer>
+
+
+<script type="text/javascript">
+ var disqus_shortname = 'm2ym-blog';
+
+
+ var disqus_script = 'count.js';
+
+ (function () {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ }());
+</script>
+
+
+
+
+
+
+
+ <script type="text/javascript">
+ (function(){
+ var twitterWidgets = document.createElement('script');
+ twitterWidgets.type = 'text/javascript';
+ twitterWidgets.async = true;
+ twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
+ document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
+ })();
+ </script>
+
+
+
+
+
+</body>
+</html>
View
122 index.html
@@ -9,17 +9,7 @@
<meta name="author" content="m2ym">
- <meta name="description" content="Octopressでブログを初めることにした。Markdown記法で書けるのが主な理由。テストがてら投稿してみる。 1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-(print (loop for i from 1 to 100 if (zerop (mod i 15)) collect &quot; &hellip;">
+ <meta name="description" content="答え:レキシカル環境が無視されるから。 実例で解説しよう。CL-Yaccというライブラリがある。名前の通りyaccをCommon Lispにポートしたものだ。実装は単純明快で、背景となる理論を知っていればすんなり読めるはずだ。 CL-Yaccはdefine-parserというマクロを提供しており、 &hellip;">
<!-- http://t.co/dKP3o1e -->
@@ -80,6 +70,112 @@
<header>
+ <h1 class="entry-title"><a href="/blog/2012/04/28/eval-in-macros/">マクロ内でevalするべきでない理由</a></h1>
+
+
+ <p class="meta">
+
+
+
+
+
+
+
+
+
+
+
+
+<time datetime="2012-04-28T17:00:00+09:00" pubdate data-updated="true">Apr 28<span>th</span>, 2012</time>
+
+ | <a href="/blog/2012/04/28/eval-in-macros/#disqus_thread">Comments</a>
+
+ </p>
+
+ </header>
+
+
+ <div class="entry-content"><p>答え:レキシカル環境が無視されるから。</p>
+
+<p>実例で解説しよう。<a href="http://www.pps.jussieu.fr/~jch/software/cl-yacc/">CL-Yacc</a>というライブラリがある。名前の通りyaccをCommon Lispにポートしたものだ。実装は単純明快で、背景となる理論を知っていればすんなり読めるはずだ。</p>
+
+<p>CL-Yaccは<code>define-parser</code>というマクロを提供しており、ユーザーはこれを用いてパーサーを定義する。以下に簡単な四則演算パーサーの例を示す。</p>
+
+<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+<span class='line-number'>2</span>
+<span class='line-number'>3</span>
+<span class='line-number'>4</span>
+<span class='line-number'>5</span>
+<span class='line-number'>6</span>
+<span class='line-number'>7</span>
+<span class='line-number'>8</span>
+<span class='line-number'>9</span>
+<span class='line-number'>10</span>
+</pre></td><td class='code'><pre><code class='common-lisp'><span class='line'><span class="p">(</span><span class="nv">yacc:define-parser</span> <span class="vg">*parser*</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:start-symbol</span> <span class="nv">expression</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:terminals</span> <span class="p">(</span><span class="nc">integer</span> <span class="nb">+</span> <span class="nb">-</span> <span class="nb">*</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">+</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">+</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">-</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">-</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">*</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">*</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">/</span> <span class="nv">expression</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span> <span class="p">(</span><span class="nb">/</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span>
+</span><span class='line'> <span class="nc">integer</span><span class="p">))</span>
+</span></code></pre></td></tr></table></div></figure>
+
+
+<p>セマンティックアクションがすべて類似していることに気付くだろう。試しに<code>macrolet</code>を使って以下のように書きかえてみる。</p>
+
+<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+<span class='line-number'>2</span>
+<span class='line-number'>3</span>
+<span class='line-number'>4</span>
+<span class='line-number'>5</span>
+<span class='line-number'>6</span>
+<span class='line-number'>7</span>
+<span class='line-number'>8</span>
+<span class='line-number'>9</span>
+<span class='line-number'>10</span>
+<span class='line-number'>11</span>
+<span class='line-number'>12</span>
+<span class='line-number'>13</span>
+<span class='line-number'>14</span>
+</pre></td><td class='code'><pre><code class='common-lisp'><span class='line'><span class="p">(</span><span class="k">macrolet</span> <span class="p">((</span><span class="nv">app</span> <span class="p">(</span><span class="nv">op</span><span class="p">)</span>
+</span><span class='line'> <span class="o">`</span><span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">_</span> <span class="nv">b</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="k">declare</span> <span class="p">(</span><span class="k">ignore</span> <span class="nv">_</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="o">,</span><span class="nv">op</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">))))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">yacc:define-parser</span> <span class="vg">*parser*</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:start-symbol</span> <span class="nv">expression</span><span class="p">)</span>
+</span><span class='line'> <span class="p">(</span><span class="ss">:terminals</span> <span class="p">(</span><span class="nc">integer</span> <span class="nb">+</span> <span class="nb">-</span> <span class="nb">*</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">+</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">+</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">-</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">-</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">*</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">*</span><span class="p">))</span>
+</span><span class='line'> <span class="p">(</span><span class="nv">expression</span> <span class="nb">/</span> <span class="nv">expression</span> <span class="p">(</span><span class="nv">app</span> <span class="nb">/</span><span class="p">))</span>
+</span><span class='line'> <span class="nc">integer</span><span class="p">)))</span>
+</span></code></pre></td></tr></table></div></figure>
+
+
+<p>ネストは深くなったが、パーサー定義はより簡潔になったはずだ。しかし、この新しい定義を評価(コンパイル)すると<code>The function APP is undefined.</code>というエラーが発生する。なぜか。</p>
+
+<p>CL-Yaccは<strong>マクロ展開時</strong>にパーサーテーブルを生成する。そのとき、セマンティックアクションも関数形式に変換して同テーブルに格納する。このような手順をとる場合、セマンティックアクションとして<code>define-parser</code>に記述されたフォーム(先の例では<code>(lambda (a _ b) ...)</code>)は<code>eval</code>で評価せざるを得ない。</p>
+
+<p><code>eval</code>に渡されたフォームは空レキシカル環境、つまりグローバル環境上で評価される。空レキシカル環境上で評価されるということは、<code>symbol-macrolet</code>や<code>macrolet</code>などのレキシカル環境に作用するオペレータが全く無効になるということである(たとえ字句的に包含していようが)。したがって、上記の<code>APP</code>は見えなかったというわけである。</p>
+
+<p>この問題は全くもってLispの力を制限するものであるから、本当に必要なときを除いて、特にマクロ展開中は、<code>eval</code>は使わないようにすべきである。</p>
+</div>
+
+
+
+
+ </article>
+
+
+ <article>
+
+ <header>
+
<h1 class="entry-title"><a href="/blog/2012/04/21/first-post/">初投稿</a></h1>
@@ -149,6 +245,10 @@ <h1 class="entry-title"><a href="/blog/2012/04/21/first-post/">初投稿</a></h1
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/2012/04/28/eval-in-macros/">マクロ内でevalするべきでない理由</a>
+ </li>
+
+ <li class="post">
<a href="/blog/2012/04/21/first-post/">初投稿</a>
</li>
View
8 sitemap.xml
@@ -5,11 +5,15 @@
<lastmod>2012-04-21T23:23:53+09:00</lastmod>
</url>
<url>
+ <loc>http://m2ym.github.com/blog/2012/04/28/eval-in-macros/</loc>
+ <lastmod>2012-04-28T18:07:43+09:00</lastmod>
+ </url>
+ <url>
<loc>http://m2ym.github.com/</loc>
- <lastmod>2012-04-21T23:23:53+09:00</lastmod>
+ <lastmod>2012-04-28T18:07:43+09:00</lastmod>
</url>
<url>
<loc>http://m2ym.github.com/blog/archives/</loc>
- <lastmod>2012-04-21T23:23:53+09:00</lastmod>
+ <lastmod>2012-04-28T18:07:43+09:00</lastmod>
</url>
</urlset>
Please sign in to comment.
Something went wrong with that request. Please try again.