⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ref.html

📁 A very small LISP implementation with several packages and demo programs.
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Pico Lisp Reference</title><link rel="stylesheet" href="doc.css" type="text/css"></head><body><a href="mailto:abu@software-lab.de">abu@software-lab.de</a><p align=right><i>Perfection is attained</i><br><i>not when there is nothing left to add</i><br><i>but when there is nothing left to take away</i><br><i>(Antoine de Saint-Exup茅ry)</i><br><h1>The Pico Lisp Reference</h1><p align=right>(c) Software Lab. Alexander Burger<p>This document describes the concepts, data types, and kernel functions of the<a href="http://software-lab.de/down.html">Pico Lisp</a> system.<p>This is <i>not</i> a Lisp tutorial. For an introduction to Lisp, atraditional Lisp book like "Lisp" by Winston/Horn (Addison-Wesley 1981) isrecommended. Note, however, that there are significant differences between PicoLisp and Maclisp (and even greater differences to Common Lisp).<p>Please take a look at the <a href="tut.html">Pico Lisp Tutorial</a> for anexplanation of some aspects of Pico Lisp, and scan through the list of <ahref="faq.html">Frequently Asked Questions (FAQ)</a>.<p><ul><li><a href="#intro">Introduction</a><li><a href="#vm">The Pico Lisp Machine</a>   <ul>   <li><a href="#cell">The Cell</a>   <li><a href="#data">Data Types</a>      <ul>      <li><a href="#number">Numbers</a>      <li><a href="#symbol">Symbols</a>         <ul>         <li><a href="#nilSym">NIL</a>         <li><a href="#internal">Internal Symbols</a>         <li><a href="#transient">Transient Symbols</a>         <li><a href="#external">External Symbols</a>         </ul>      <li><a href="#lst">Lists</a>      </ul>   <li><a href="#mem">Memory Management</a>   </ul><li><a href="#penv">Programming Environment</a>   <ul>   <li><a href="#invoc">Invocation</a>   <li><a href="#io">Input/Output</a>      <ul>      <li><a href="#num-io">Numbers</a>      <li><a href="#sym-io">Symbols</a>         <ul>         <li><a href="#nilSym-io">NIL</a>         <li><a href="#internal-io">Internal Symbols</a>         <li><a href="#transient-io">Transient Symbols</a>         <li><a href="#external-io">External Symbols</a>         </ul>      <li><a href="#lst-io">Lists</a>      <li><a href="#macro-io">Read-Macros</a>      </ul>   <li><a href="#ev">Evaluation</a>   <li><a href="#int">Interrupt</a>   <li><a href="#errors">Error Handling</a>   <li><a href="#atres">@ Result</a>   <li><a href="#cmp">Comparing</a>   <li><a href="#oop">OO Concepts</a>   <li><a href="#dbase">Database</a>   <li><a href="#pilog">Pico Lisp Prolog</a>   <li><a href="#conv">Naming Conventions</a>   <li><a href="#trad">Breaking Traditions</a>   <li><a href="#bugs">Bugs</a>   </ul><li><a href="#fun">Function Reference</a><li><a href="#down">Download</a></ul><p><hr><h2><a name="intro">Introduction</a></h2><p>Pico Lisp is the result of a language design study, trying to answer thequestion "What is a minimal but useful architecture for a virtual machine?".Because opinions differ about what is meant by "minimal" and "useful", there aremany answers to that question, and people might consider other solutions more"minimal" or more "useful". But from a practical point of view, Pico Lisp hasproven to be a valuable answer to that question.<p>First of all, Pico Lisp is a virtual machine architecture, and then aprogramming language. It was designed in a "bottom up" way, and "bottom up" isalso the most natural way to understand and to use it: <i>Form FollowsFunction</i>.<p>Pico Lisp has been used in several commercial and research programmingprojects since 1988. Its internal structures are simple enough, allowing anexperienced programmer always to fully understand what's going on under thehood, and its language features, efficiency and extensibility make it suitablefor almost any practical programming task.<p>In a nutshell, emphasis was put on four design objectives. The Pico Lispsystem should be<p><dl><dt>Simple<dd>The internal data structure should be as simple as possible. Only one singledata structure is used to build all higher level constructs.<dt>Unlimited<dd>There are no limits imposed upon the language due to limitations of thevirtual machine architecture. That is, there is no upper bound in symbol namelength, number digit counts, stack depth, or data structure and buffer sizes,except for the total memory size of the host machine.<dt>Dynamic<dd>Behavior should be as dynamic as possible ("run"-time vs. "compile"-time).All decisions are delayed till runtime where possible. This involves matterslike memory management, dynamic symbol binding, and late method binding.<dt>Practical<dd>Pico Lisp is not just a toy of theoretical value. It is in use since 1988 inactual application development, research and production.</dl><p><hr><h2><a name="vm">The Pico Lisp Machine</a></h2><p>An important point in the Pico Lisp philosophy is the knowledge about thearchitecture and data structures of the internal machinery. The high-levelconstructs of the programming language directly map to that machinery, makingthe whole system both understandable and predictable.<p>This is similar to assembly language programming, where the programmer hascomplete control over the machine.<p><hr><h3><a name="cell">The Cell</a></h3><p>The Pico Lisp virtual machine is both simpler and more powerful than mostcurrent (hardware) processors. At the lowest level, it is constructed from asingle data structure called "cell":<p><pre><code>         +-----+-----+         | CAR | CDR |         +-----+-----+</code></pre><p>A cell is a pair of machine words, which traditionally are called CAR and CDRin the Lisp terminology. These words can represent either a numeric value(scalar) or the address of another cell (pointer). All higher level datastructures are built out of cells.<p>The type information of higher level data is contained in the pointers tothese data. Assuming the implementation on a byte-addressed physical machine,and a pointer size of typically 4 bytes, each cell has a size of 8 bytes.Therefore, the pointer to a cell must point to an 8-byte boundary, and itsbit-representation will look like:<p><pre><code>      xxxxxxxxxxxxxxxxxxxxxxxxxxxxx000</code></pre><p>(the <code>'x'</code> means "don't care"). For the individual data types, thepointer is adjusted to point to other parts of a cell, in effect setting some ofthe lower three bits to non-zero values. These bits are then used by theinterpreter to determine the data type.<p>In any case, bit(0) - the least significant of these bits - is reserved as amark bit for garbage collection.<p>Initially, all cells in the memory are unused (free), and linked together toform a "free list". To create higher level data types at runtime, cells aretaken from that free list, and returned by the garbage collector when they areno longer needed. All memory management is done via that free list; there are noadditional buffers, string spaces or special memory areas (With two exceptions:A certain fixed area of memory is set aside to contain the executable code andglobal variables of the interpreter itself, and a standard push down stack forreturn addresses and temporary storage. Both are not directly accessible by theprogrammer).<p><hr><h3><a name="data">Data Types</a></h3><p>On the virtual machine level, Pico Lisp supports<p><ul><li>three base data types: Numbers, Symbols and Cons Pairs (Lists)<li>the three scope variations of symbols: Internal, Transient and External<li>and the special symbol <code>NIL</code>.</ul><p>They are all built from the single cell data structure, and all runtime datacannot consist of any other types than these three.<p>The following diagram shows the complete data type hierarchy, consisting ofthe three base types and the symbol variations:<p><pre><code>                    cell                     |            +--------+--------+            |        |        |         Number    Symbol    List                     |                     |   +--------+--------+--------+   |        |        |        |  NIL   Internal Transient External</code></pre><p><hr><h4><a name="number">Numbers</a></h4><p>A number can represent a signed integral value of arbitrary size. The CARs ofone or more cells hold the number's "digits" (each in the machine's word size),to store the number's binary representation.<p><pre><code>         Number         |         V      +-----+-----+     +-----+-----+     +-----+-----+      |'DIG'|  ---+---> |'DIG'|  ---+---> |'DIG'|  /  |      +-----+-----+     +-----+-----+     +-----+-----+</code></pre><p>The first cell holds the least significant digit. The least significant bitof that digit represents the sign.<p>The pointer to a number points into the middle of the CAR, with an offset of2 from the cell's start address. Therefore, the bit pattern of a number will be:<p><pre><code>      xxxxxxxxxxxxxxxxxxxxxxxxxxxxx010</code></pre><p>Thus, a number is recognized by the interpreter when bit(1) is non-zero.<p><hr><h4><a name="symbol">Symbols</a></h4><p>A symbol is more complex than a number. Each symbol has a value, andoptionally a name and an arbitrary number of properties. The CDR of a symbolcell is also called VAL, and the CAR points to the symbol's tail. As a minimum,a symbol consists of a single cell, and has no name or properties:<p><pre><code>            Symbol            |            V      +-----+-----+      |  /  | VAL |      +-----+-----+</code></pre><p>That is, the symbol's tail is empty (points to <code>NIL</code>, as indicatedby the '/' character).<p>The pointer to a symbol points to the CDR of the cell, with an offset of 4from the cell's start address. Therefore, the bit pattern of a symbol will be:<p><pre><code>      xxxxxxxxxxxxxxxxxxxxxxxxxxxxx100</code></pre><p>Thus, a symbol is recognized by the interpreter when bit(2) is non-zero.<p>A property is a key-value-pair, represented as a cell in the symbol's tail.This is called a "property list". The property list may be terminated by anumber representing the symbol's name. In the following example, a symbol withthe name <code>"abc"</code> has three properties:<p><pre><code>            Symbol            |            V      +-----+-----+      |  |  | VAL |      +--+--+-----+         | tail         |         V                                                      name         +-----+-----+     +-----+-----+     +-----+-----+     +-----+-----+         |  |  |  ---+---> | KEY |  ---+---> |  |  |  ---+---> |'cba'|  /  |         +--+--+-----+     +-----+-----+     +--+--+-----+     +-----+-----+            |                                   |            V                                   V            +-----+-----+                       +-----+-----+            | VAL | KEY |                       | VAL | KEY |            +-----+-----+                       +-----+-----+</code></pre><p>Each property in a symbol's tail is either a symbol (then it represents aboolean value), or a cell with the property key in its CDR and the propertyvalue in its CAR. In both cases, the key should be a symbol, because searches inthe property list are performed using pointer comparisons.<p>The name of a symbol is stored as a number at the end of the tail. Itcontains the characters of the name in UTF-8 encoding, using between one andthree 8-bit-bytes per character. The first byte of the first character is storedin the lowest 8 bits of the number.<p>All symbols have the above structure, but depending on scope andaccessibility there are actually four types of symbols: <code><ahref="#nilSym">NIL</a></code>, <a href="#internal">internal</a>, <ahref="#transient">transient</a> and <a href="#external">external</a> symbols.<p><hr><h5><a name="nilSym">NIL</a></h5><p><code>NIL</code> is a special symbol which exists exactly once in the wholesystem. It is used<p><ul><li>as an end-of-list marker<li>to represent the empty list<li>to represent the boolean value "false"<li>to represent a string of length zero<li>to represent the value "Not a Number"<li>as the root of all class hierarchies</ul><p>For that, <code>NIL</code> has a special structure:<p><pre><code>      NIL:  /            |            V      +-----+-----+-----+-----+      |  /  |  /  |  /  |  /  |      +-----+--+--+-----+-----+</code></pre><p>The reason for that structure is <code>NIL</code>'s dual nature both as asymbol and as a list:<p><ul><li>As a symbol, it should give <code>NIL</code> for its VAL, and be withoutproperties<li>For the empty list, <code>NIL</code> should give <code>NIL</code> both forits CAR and for its CDR</ul><p>These requirements are fulfilled by the above structure.<p><hr><h5><a name="internal">Internal Symbols</a></h5><p>Internal Symbols are all those "normal" symbols, as they are used forfunction definitions and variable names. They are "interned" into a hashed liststructure, so that it is possible to find an internal symbol by searching forits name.<p>There cannot be two different internal symbols with the same name.<p>Initially, a new internal symbol's VAL is <code>NIL</code>.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -