41 lines
8.9 KiB
HTML
41 lines
8.9 KiB
HTML
<!DOCTYPE html PUBLIC ""
|
||
"">
|
||
<html><head><meta charset="UTF-8" /><title>M-Expressions</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">Beowulf</span> <span class="project-version">0.3.0-SNAPSHOT</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Topics</span></h3><ul><li class="depth-1 "><a href="intro.html"><div class="inner"><span>beowulf</span></div></a></li><li class="depth-1 current"><a href="mexpr.html"><div class="inner"><span>M-Expressions</span></div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>beowulf</span></div></div></li><li class="depth-2 branch"><a href="beowulf.bootstrap.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>bootstrap</span></div></a></li><li class="depth-2 branch"><a href="beowulf.cons-cell.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>cons-cell</span></div></a></li><li class="depth-2 branch"><a href="beowulf.core.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>core</span></div></a></li><li class="depth-2 branch"><a href="beowulf.gendoc.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>gendoc</span></div></a></li><li class="depth-2 branch"><a href="beowulf.host.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>host</span></div></a></li><li class="depth-2 branch"><a href="beowulf.io.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>io</span></div></a></li><li class="depth-2 branch"><a href="beowulf.manual.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>manual</span></div></a></li><li class="depth-2 branch"><a href="beowulf.oblist.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>oblist</span></div></a></li><li class="depth-2 branch"><a href="beowulf.read.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>read</span></div></a></li><li class="depth-2"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>reader</span></div></div></li><li class="depth-3 branch"><a href="beowulf.reader.char-reader.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>char-reader</span></div></a></li><li class="depth-3 branch"><a href="beowulf.reader.generate.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>generate</span></div></a></li><li class="depth-3 branch"><a href="beowulf.reader.macros.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>macros</span></div></a></li><li class="depth-3 branch"><a href="beowulf.reader.parser.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>parser</span></div></a></li><li class="depth-3"><a href="beowulf.reader.simplify.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>simplify</span></div></a></li><li class="depth-2"><a href="beowulf.scratch.html"><div class="inner"><span class="tree" style="top: -176px;"><span class="top" style="height: 185px;"></span><span class="bottom"></span></span><span>scratch</span></div></a></li></ul></div><div class="document" id="content"><div class="doc"><div class="markdown"><h1><a href="#m-expressions" name="m-expressions"></a>M-Expressions</h1>
|
||
<p>M-Expressions (‘mexprs’) are the grammar which John McCarthy origininally used to write Lisp, and the grammar in which many of the function definitions in the <a href="https://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf">Lisp 1.5 Programmer’s Manual</a> are stated. However, I have not seen anywhere a claim that Lisp 1.5 could <em>read</em> M-Expressions, and it is not clear to me whether it was even planned that it should do so.</p>
|
||
<p>Rather, it seems to me probably that M-Expressions were only ever a grammar intended to be written on paper, like <a href="https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form">Backus Naur Form</a>, to describe and to reason about algorithms.</p>
|
||
<p>I set out to make Beowulf read M-Expressions essentially out of curiousity, to see whether it could be done. I had this idea that if it could be done, I could implement most of Lisp 1.5 simply by copying in the M-Expression definitions out of the manual.</p>
|
||
<p>Consequently, the Beowulf parser can parse the M-Expression grammar as stated in the manual, and generate S-Expressions from it according to the table specified on page 10 of the manual.</p>
|
||
<p>There are two problems with this.</p>
|
||
<h2><a href="#problems-with-interpreting-m-expressions" name="problems-with-interpreting-m-expressions"></a>Problems with interpreting M-Expressions</h2>
|
||
<h3><a href="#generating-idiomatic-lisp" name="generating-idiomatic-lisp"></a>Generating idiomatic Lisp</h3>
|
||
<p>In the M-Expression notation, a lower case character or sequence of characters represents a variable; an upper case character represents a constant. As the manual says,</p>
|
||
<blockquote>
|
||
<p>2 . The obvious translation of letting a constant translate into itself will not work. Since the translation of <code>x</code> is <code>X</code>, the translation of <code>X</code> must be something else to avoid ambiguity. The solution is to quote it. Thus <code>X</code> is translated into <code>(QUOTE X)</code>.</p>
|
||
</blockquote>
|
||
<p>Thus, necessarily, the translation of a constant must always be quoted. In practice, key constants in Lisp such as <code>T</code> are bound to themselves, so it is idiomatic in Lisp, certainly in the way we have learned to use it, to write, for example,</p>
|
||
<pre><code>(SET (QUOTE NULL)
|
||
(QUOTE (LAMBDA (X)
|
||
(COND
|
||
((EQUAL X NIL) T) (T F)))))
|
||
</code></pre>
|
||
<p>However, the literal translation of</p>
|
||
<pre><code>null[x] = [x = NIL -> T; T -> F]
|
||
</code></pre>
|
||
<p>is</p>
|
||
<pre><code>(SET (QUOTE NULL)
|
||
(QUOTE (LAMBDA (X)
|
||
(COND
|
||
((EQUAL X (QUOTE NIL)) (QUOTE T))
|
||
((QUOTE T) (QUOTE F))))))
|
||
</code></pre>
|
||
<p>This is certainly more prolix and more awkward, but it also risks being flat wrong.</p>
|
||
<p>Is the value of <code>NIL</code> the atom <code>NIL</code>, or is it the empty list <code>()</code>? If the former, then the translation from the M-Expression above is correct. However, that means that recursive functions which recurse down a list seeking the end will fail. So the latter must be the case.</p>
|
||
<p><code>NULL</code> is described thus (Ibid, p11):</p>
|
||
<blockquote>
|
||
<p>This is a predicate useful for deciding when a list is exhausted. It is true if and only if its argument is <code>NIL</code>.</p>
|
||
</blockquote>
|
||
<p><code>NIL</code> is used explicitly in an M-Expression for example in the definition of <code>intersection</code> (Ibid, p15).</p>
|
||
<p>I think there is an ambiguity in referencing constants which are not bound to themselves in the M-Expression notation as given in the manual. This is particularly problematic with regards to <code>NIL</code> and <code>F</code>, but there may be others instances.</p>
|
||
<h3><a href="#curly-braces" name="curly-braces"></a>Curly braces</h3>
|
||
<p>The use of curly braces is not defined in the grammar as stated on page 10. They are not used in the initial definition of <code>APPLY</code> on page 13, but they are used in the more developed restatement on page 70. I believe they are to be read as indicating a <code>DO</code> statement – a list of function calls to be made sequentially but without strict functional dependence on one another – but I don’t find the exposition here particularly clear and I’m not sure of this.</p>
|
||
<p>Consequently, the M-Expression interpreter in Beowulf does not interpret curly braces.</p></div></div></div></body></html> |