Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > e3d62627d1d1aab7ab1be2dd7f65a872 > files > 237

ecl-10.4.1-1.fc14.x86_64.rpm

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;3.&#160;Data and control flow</title><link rel="stylesheet" href="ecl.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.2"><link rel="home" href="index.html" title="The ECL manual"><link rel="up" href="pt01.html" title="Part&#160;I.&#160;Standards"><link rel="prev" href="ch02.html" title="Chapter&#160;2.&#160;Evaluation and compilation"><link rel="next" href="ch03s02.html" title="3.2.&#160;Functions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;3.&#160;Data and control flow</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02.html">Prev</a>&#160;</td><th width="60%" align="center">Part&#160;I.&#160;Standards</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch03s02.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter&#160;3.&#160;Data and control flow"><div class="titlepage"><div><div><h2 class="title"><a name="ansi.data-and-control"></a>Chapter&#160;3.&#160;Data and control flow</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ch03.html#ansi.minimal-compilation">3.1. Minimal compilation</a></span></dt><dt><span class="section"><a href="ch03s02.html">3.2. Functions</a></span></dt></dl></div><div class="section" title="3.1.&#160;Minimal compilation"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ansi.minimal-compilation"></a>3.1.&#160;Minimal compilation</h2></div></div></div><p>Former versions of <span class="application">ECL</span>, as well as many other lisps, used linked
  lists to represent code. Executing code thus meant traversing these lists
  and performing code transformations, such as macro expansion, every time
  that a statement was to be executed. The result was a slow and memory
  hungry interpreter.</p><p>Beginning with version 0.3, <span class="application">ECL</span> was shipped with a bytecodes
  compiler and interpreter which circumvent the limitations of linked
  lists. When you enter code at the lisp prompt, or when you load a source
  file, <span class="application">ECL</span> begins a process known as minimal compilation. Barely this
  process consists on parsing each form, macroexpanding it and translating it
  into an intermediate language made of
  <span class="emphasis"><em>bytecodes</em></span>.</p><p>The bytecodes compiler is implemented in
  <code class="filename">src/c/compiler.d</code>. The main entry point is the lisp
  function <code class="function">si::make-lambda</code>, which takes a name for the
  function and the body of the lambda lists, and produces a lisp object that
  can be invoked. For instance,
  </p><pre class="screen">&gt; (defvar fun (si::make-lambda 'f '((x) (1+ x))))
*FUN*
&gt; (funcall fun 2)
3</pre><p><span class="application">ECL</span> can only execute bytecodes. When a list is passed to
  <code class="literal">EVAL</code> it must be first compiled to bytecodes and, if the
  process succeeds, the resulting bytecodes are passed to the
  interpreter. Similarly, every time a function object is created, such as in
  <code class="function">DEFUN</code> or <code class="function">DEFMACRO</code>, the compiler
  processes the lambda form to produce a suitable bytecodes object.</p><p>The fact that <span class="application">ECL</span> performs this eager compilation means that
  changes on a macro are not immediately seen in code which was already
  compiled. This has subtle implications. Take the following code:</p><pre class="screen">&gt; (defmacro f (a b) `(+ ,a ,b))
F
&gt; (defun g (x y) (f x y))
G
&gt; (g 1 2)
3
&gt; (defmacro f (a b) `(- ,a ,b))
F
&gt; (g 1 2)
3</pre><p>The last statement always outputs <code class="literal">3</code> while in former
  implementations based on simple list traversal it would produce
  <code class="literal">-1</code>.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="pt01.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch03s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;2.&#160;Evaluation and compilation&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;3.2.&#160;Functions</td></tr></table></div></body></html>