pure_LISP tutorial
[ Index ] [ LISP reference
] [ LISP tutorial ] [ SECD
collection ] [ SECD reference ]
This document describes the installation and introduction to the package
SECD_Mania, especially the final part of the package
- pure_LISP language and its implementation base
- the virtual SECD machine.
1. Introduction.
pure_LISP is a pure LISP implementation for GNU/Linux OS, based on an
advanced version of SECD virtual machine.
The language have the following properties:
- functional language with lexical scope bindings and a LISP-like syntax.
- fully TailRecursive program control.
- lazy evaluations.
- multitasking and timesharing.
- fully asynchronous file and TCP connection handling.
- interprocess message passing mechanism.
The properties, omited in the language:
- wide range of data types (only atoms and integers are terminal types
now).
- atom space is not indexed and garbage collector doesn't work on it.
- error and exception handling.
- links to other languages and OS libraries.
2. Installation.
Download the pure_LISP from here.
Mirrors:
skelet.ludost.net
skelet.hit.bg/SECD
Requirements: You must have FreePascal installed on your system.
If you use Debian Linux, simply type:
apt-get install fp-compiler binutils
If you use some other Linux, go to FreePascal home page for instructions.
Usage:
Download the package in some new directory (i prefer 'secd'), then type:
tar xzf LISP_0.6.tar.gz
Now you have the package sources in subdirectory Base_2.
Type:
cd Base_2
./make_all
After this, SECD virtual machine will be compiled and started. (read
the make_all shell script for details). The machine loads and executes
the SECD code from the file init.sec. This code defines a small miniOS program.
The following lines appear on the console:
Reading code init.sec ...
Executing code ...
SEC>
Now type at the prompt:
(add 2 5)
miniOS will respond to you:
SEC>(add 2 5)
(#ldc 2 #ldc 5 #add)
7
SEC>
The first line of the response - list (#ldc 2 #ldc 5 #add) is a SECD code, compiled version of your command (add 2
5). This code is then executed and the result - integer number 7 in this examle
is printed on the conslole.
Try a more complex expression:
SEC>(let (mul a a) (a add 2 3))
(#delay
(#ldc 2 #ldc 3 #add)
#trlet_1 #ld_0_0 #rec #ld_0_0 #trrec_mul)
25
SEC>
The above expression is a pure_LISP record for the mathematical notation:
Let a is the sum of 2 and 3.
Evaluate a multiplied by a and give the result.
More info about possible pure_LISP functions you may find in pure_LISP reference.
3. Files in the package.
Open a new console and go to the pure_LISP package subdirectory (in my
computer this is /home/skelet/secd/Base_2).
Type:
ls -l
Computer will show you the package files and subdirectories.
These files may be arranged in some different groups:
- secd is the main program of the package - SECD virtual machine
interpreter.
Usage: ./secd code_name
Example: ./secd init
will execute the secd code from the file 'init.sec'.
- meta is a subdirectory, containing pascal sources, defining
SECD machine:
- secd.pp is the main program
- secd_mem.pp defines SECD data types, list meta commands
and garbage collectors.
- secd_cod.pp is the main part of the SECD machine interpreter.
- secd_str.pp defines atom and file handling.
- secd_msg.pp defines send/recv SECD commands.
- secd_tcp.pp defines TCP handling.
- make_all is a shell script. It compiles and runs the SECD
interpreter.
- Changes.txt describes differences from the previos machine
(in bigger package SECD Mania).
- sysfun.txt is a list of the names and types for compiler defined
functions.
- secd.log is log file, where the working SECD machine will
write some statistics and error messages.
- *.lsp and *.lib files are pure_LISP sources for programs
and libraries:
- init.lsp is the main loop of the miniOS.
- shell.lsp is the shell loop of the miniOS.
- rtl.lsp is the definition of the RTL for the miniOS.
- client.lsp is a simple client who talks with the miniOS
using TCP connection.
- system.lib is a library for the basic I/O and other functions.
- sysboot.lib is restricted version of system.lib, used from
init.lsp.
- compiler.lib is a library containing the compiler sources.
- numbers.lib is a library for all numeric examples.
- sysmono.lib is old version of system.lib, used by non-deterministic
examples.
- *.sec files are pure_LISP program codes (SECD codes):
- init.sec, rtl.sec and shell.sec are all codes of
the miniOS server.
- client.sec is program code for miniOS client.
- cli_0, cli_1 subdirectories are created with only purpose
to hold the 'secd.log' file for other started copies of the secd program.
I use them to start new client connections to the miniOS server. First
I open new Linux console, then:
cd cli_0
../secd client
After this, new miniOS shell is started. All works are done by the
miniOS server (init.sec code). Program client.sec is only mediator between
new console and the server.
- html subdirectory contains documentation for pure_LISP:
- In Numbers subdirectory are defined some infinite sequences
from the theory of numbers.
- Examples subdirectory contains other examples.
4. pure_LISP examples.
For the most of the examples the following procedure must be used to
start them correctly:
- first copy the example source from its directory (Numbers or Examples)
into the main directory.
This must be done in Linux shell:
cp example_dir/example_name.lsp .
- compile the example in SEC shell:
(comp_lsp (quote example_name))
- execute the example:
(exec (quote example_name))
Examples in subdirectory Numbers demonstrate the usage of infinite
sequences in lazy evaluations. They all uses the library numbers.lib. In this
library are defined lists of all numbers, prime numbers and pitagorean triples.
But in final expression only limited part of these lists may be evaluated
and printed (if we try to print all numbers, some overflow will happens).
Numbers content:
- fiblist prints first 30 Fibonachy numbers.
- pitlazy prints first 100 Pitagorean triples.
- pitfast prints first 1000 Pitagorean triples, but uses more
mathematics and is faster.
- primes prints first 1000 prime numbers.
- prmember prints the 2000-th prime number.
- twins prints first 1000 prime numbers twins.
Examples content:
- fac evaluates 10! (1*2*3...*10).
- test increase all elements of the list (1 2 3 4 5) and then
reverse the result.
- queens is a non-deterministic solution of the problem '8 queens'.
It must be executed alone (not in miniOS). To do this, first compile
the program, then terminate the miniOS and type:
./secd queens
- pitmono is non-deterministic program, evaluating some pitagorean
triples.
It is like queens and must be executed alone.
- pitagor is like pitmono but it is addopted to be used
in miniOS.
Little changes in this program or into the pure_LISP evaluation model
may crash the evaluation.
- queens_bad is an example of incorrect non-deterministic program.
The incorrectness is a result of mixing of the laziness and parallelism
into one step. Compare it with more proper program queens.
More about problems with non-deterministic examples and their miniOS
variants you may read in file Changes.txt.
(c) Skelet, Sep 2002 in terms of GNU GPL
Mail me at home or work