ShenDoc 30




The means of achieving Shen involved developing a small fast Lisp called Kλ which is rich enough to encode Qi, but small enough to be easily mapped into other platforms or implemented as a standalone.

In terms of design, Kλ reflects the following design criteria.

1. It should be powerful enough to express Qi.

2. It should be minimal, with very few primitives and so easy to implement. No macros, optional arguments etc. because Shen can support all these things already.

3. It is not designed as a language to compete against Common Lisp; deliberately. It is a Lisp assembly language for a higher level language. The minimalism is deliberate.

4. It should be clean; i.e. it should support partial applications, lexical scoping and tail recursion optimisation.

5. It should be fast; it should support type declarations.

Some comparable small Lisps to Kλ are PicoLisp, FemtoLisp, TinyScheme and SmallLisp.

Unlike Common Lisp, Kλ is very portable over different platforms. In place of Common Lisp's 1150 pages of specification, Kλ requires only 46 system functions. It is much easier to develop a stand-alone implementation of Kλ than to build a complete version of CL. Even more significantly, it is possible to map Kλ into popular existing platforms such as Clojure, Python as well as Common Lisp.

The implementation, Shen, attached to this document runs Qi on this reduced instruction set and, in terms of primitives required, has nearly 1/3 of the footprint of Qi II. Shen is entirely defined in Kλ. Hence Shen is no more difficult to port than Kλ itself. All that needs to be done is to map the simple reduced instruction set of Kλ into the chosen platform. Our distribution in fact contains one such mapping - of Kλ to Common Lisp; and this is done in 250 lines of code.

Kλ misses many of the features of bigger Lisps (like macros) because Shen effectively incorporates many of these features. Even LIST and QUOTE are missing from Kλ because they are not needed for Shen and Qi has never needed or missed them. Similarly we do not impose a comment convention on Kλ because we do not consider that people need to or should write in Kλ. The emphasis is on devising an absolutely efficient minimal set needed to port Qi which is easy for people to code in other languages.

However anybody who implements Kλ, and wants to write directly in this notation, can add extra features to their implementation to Kλ. This does not affect the standard; just as a CL which includes (e.g.) threads does not cease to be a CL even though it incorporates a non-standard feature. However the systems code for Shen will not rely on extra features outside the standard. It is intentionally minimal.


Basic Types in Shen and Kλ
The Primitive Functions of Kλ
The Syntax of Kλ
Notes on the Implementation of Kλ
Boolean Operators
The Syntax of Symbols
The Semantics of Symbols in Shen and Kλ
Strings and Pattern Matching
Character Streams and Byte Streams
Bytes and Unicode
Reader Macros
Standard Vectors and Pattern Matching
Non-standard Vectors and Tuples
Generic Functions
Type Declarations
External Global Variables
Property Lists and Hashing
Error Handling
Floats and Integers
The Timer
Special Forms

Built by Shen Technology (c) Mark Tarver, September 2021