Pure+LisP+Tutorial

2. Installation.
**Download** the pure_LISP from [|here]. Old mirrors: [|skelet.ludost.net] [|skelet.hit.bg/SECD] **Requirements:** You must have [|FreePascal] installed on your system. If you use Debian Linux, simply type: code apt-get install fp-compiler binutils code If you use some other Linux, go to [|FreePascal] home page for instructions. **Note:** code There is some troubles with the new versions of Free Pascal (Version 1.9.x and higher). One of the meta files (sec_drivers.pp) uses the Linux unit. This unit must be replaced with the new units Unix and BaseUnix in future versions, but now (October 2004) i use the unit OldLinux instead of Linux to resolve current dependencies. This change is made only in sub-package Base_4. code **Usage:** Download the package in some new directory (i prefer 'secd'), then type: code tar xzf LISP_0.8.tar.gz code Now you have the package sources in subdirectory Base_4. Type: code cd Base_4 ./make_all code After this, SECD virtual machine will be compiled and started. (read the **make_all** shell script for details). code

code The bootstrap process is simple - first the strict_LISP program kernel.sec is loaded and started. code

code Kernel, together with SECD machine emulates multitasking system. code

code The first task loaded and executed is the SECD code from the file miniOS.sec. This code defines a small miniOS program.

The following lines appear on the console: code Loading /home/YourAccount/secd/Base_4/kernel.sec ... Executing kernel ... Loading miniOS ........ Done SEC> Now type at the prompt: code code (add 2 5) miniOS will respond to you: code code 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. code Try a more complex expression: code 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. code 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_4). Type: code ls -l Computer will show you the package files and subdirectories. code These files may be arranged in some different groups: > Usage: ./secd [//code_name//] > Example: ./secd miniOS > will execute the secd code from the file 'miniOS.sec'. > For more detailed explanation of SECD bootstrap process see [|implementation scheme]. > ../secd client After this, new miniOS shell console is started. All works are done by the miniOS server (miniOS.sec code). Program client.sec is only mediator between new console and the server.
 * **secd** is the main program of the package - SECD virtual machine interpreter.
 * **meta** is a subdirectory, containing pascal sources, defining SECD machine:
 * **secd.pp** is the main program
 * **sec_lists.pp** defines SECD data types, list meta commands and garbage collectors.
 * **sec_codes.pp** defines the SECD machine interpreter.
 * **sec_atoms.pp** defines the atom space and lexeme handling.
 * **sec_drivers.pp** defines file and 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).
 * ***.lst** files contains some data:
 * **sysfun.lst** is a list of the names and associated info for compiler defined pure_LISP functions.
 * **krn_fun.lst** is a list of the names and associated info for compiler defined strict_LISP functions.
 * **errors.lst** is a list of sentences about run time errors.
 * **secd.log** is log file, where the working SECD machine will write some statistics and error messages.
 * **kernel.sys** is the source of the strict_LISP kernel. See [|implementation] for more info.
 * ***.lsp** and ***.lib** files are pure_LISP sources for programs and libraries:
 * **miniOS.lsp** is the main part of the miniOS. It uses the libs system, btree and compiler.
 * **client.lsp** is a simple client who talks with the miniOS using TCP connection.
 * **strict.lsp** is a strict_LISP compiler. It is used for compilation of the kernel only.
 * **system.lib** is a library for the basic I/O and other functions.
 * **btree.lib** is a library for some binary tree utilities, used by the compiler.
 * **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):
 * **miniOS.sec** is the code of the miniOS server.
 * **client.sec** is program code for miniOS client.
 * **kernel.sec** is the kernel code.
 * **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
 * **html** subdirectory contains documentation for pure_LISP:
 * **[|Tutorial]** - this page
 * **[|Reference]** manual
 * **[|SECD]** virtual machine manual.
 * **[|Implementation]** aspects of this package.
 * 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: > This must be done in Linux shell: cp //example_dir/example_name//.lsp. 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: **Examples** content: > It must be executed alone (not in miniOS). To do this, first compile the program, then terminate the miniOS and type: ./secd queens > It is like **queens** and must be executed alone. > Little changes in this program or into the pure_LISP evaluation model may crash the evaluation. More about problems with non-deterministic examples and their miniOS variants you may read in file ../History.txt.
 * first copy the example source from its directory (Numbers or Examples) into the main directory.
 * compile the example in SEC shell: (comp_lsp (quote //example_name//))
 * execute the example: (exec (quote //example_name//))
 * **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.
 * **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'.
 * **pitmono** is non-deterministic program, evaluating some pitagorean triples.
 * **pitagor** is like **pitmono** but it is addopted to be used in miniOS.
 * **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**.