## The Primitive Functions of KLambda
The following set represents the set of 46 primitive functions which Shen requires and which are
used in Kλ. All other functions are included in the Shen sources. The CL definitions are given to
explain the semantics of these functions. Note in some cases these primitives can be reduced still further
(e.g and in terms of if etc). In fact lambda alone is sufficient, but impractical. The instruction set is
therefore a balance between economy of primitives (easy to implement but inefficient in execution) and
practicality (more difficult to implement but possibly faster).
Kλ uses strict applicative order evaluation except for the boolean operations etc. which follow
the usual pattern. NIL is just a symbol with no special status. () denotes the empty list.
Boolean Operations (4)
if | boolean test | boolean --> A --> A --> A |
and | boolean and | boolean --> boolean --> boolean |
or | boolean or | boolean --> boolean --> boolean |
cond | case form | none |
Symbols (1)
intern | maps a string containing a symbol to a symbol | none |
Strings (7)
pos | given a natural number 0 ... n
and a string S returns
the nth unit string in S | string --> number --> string |
tlstr | returns all but the first
unit string of a string | string --> string |
cn | concatenates two strings | string --> string --> string |
str | maps any atom to a string | A --> string |
string? | test for strings | A --> boolean |
n->string | maps a code point in decimal
to the corresponding unit string | number --> string |
string->n | maps a unit string to the
corresponding decimal | string --> number |
Assignments (2)
set | assigns a value to a symbol | (value X) : A;
X : symbol;
Y : A;
______________
(set X Y) : A; |
value | retrieves the value of a symbol | |
Error Handling (3)
simple-error | prints an exception | string --> A |
trap-error | evaluates its first argument A;
if it is not an exception
returns the normal form of A
else applies its second argument
to the exception
| A --> (exception --> A) --> A |
error-to-string | maps an exception to a string | exception --> string |
Lists (4)
cons | add an element to the front of a list | A --> (list A) --> (list A) |
hd | take the head of a list _ | none |
tl | return the tail of a list | (list A) --> (list A) |
cons? | test for non-empty list | A --> boolean |
Generic Functions (7)
defun | basic Lisp function definer | none |
lambda | lambda function | X : A >> Y : B;
_____________________
(lambda X Y) : (A --> B); |
let | local assignment | Y : B;
X : B >> Z : A;
(let X Y Z ) : A; |
= | equality | A --> A --> boolean |
eval-kl | evaluation function | none |
freeze | creates a continuation | A --> (lazy A) |
type | labels the type of an expression | X : A;
___________
(type X A) : A; |
Vectors (4)
absvector | creates a vector in the native platform | none |
address-> | destructively assigns a value to a vector address | none |
<-address | retrieves a value from a vector address | none |
absvector? | recognises vectors | A --> boolean |
Streams and I/O (6)
write-byte | writes an unsigned 8 bit byte to a stream | number --> (stream out) --> number |
read-byte | reads an unsigned 8 bit byte from a stream | (stream in) --> number |
open | open a stream | if D = in or D = out
Path : string;
_______________
(open P D) : (stream D); |
close | close a stream | (stream A) --> (list B) |
Time (1)
get-time | get the run/real time | symbol --> number |
Arithmetic (9)
+ | addition | number --> number --> number |
- | subtraction | number --> number --> number |
* | multiplication | number --> number --> number |
/ | division | number --> number --> number |
> | greater than | number --> number --> boolean |
< | less than | number --> number --> boolean |
>= | greater than or equal to | number --> number --> boolean |
<= | less than or equal to | number --> number --> boolean |
number? | number test | A --> boolean |
Total 46 functions |
Acknowledgements
Kλ
History
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λ
Packages
Prolog
Shen-YACC
Strings
Strings and Pattern Matching
Lists
Streams
Character Streams and Byte Streams
Bytes and Unicode
Reader Macros
Vectors
Standard Vectors and Pattern Matching
Non-standard Vectors and Tuples
Equality
I/O
Generic Functions
Eval
Type Declarations
External Global Variables
Property Lists and Hashing
Error Handling
Numbers
Floats and Integers
The Timer
Comments
Special Forms |