ShenDoc 30


 

 

Generic Functions

This section deals with the generic functions; defun, let, lambda, eval-kl, freeze and thaw.

defun

'defun' in Kλ requires little explanation except to note that 'defun' is a top level construction and there is no obligation to support the evaluation of 'defun' within an expression; this also holds true of 'define' unless it is used in a package.

Before the S series of kernels, it was mandatory that all functions defined by 'defun' sustain currying and hence partial applications. This is now handled by the Shen reader and not Kλ.

lambda

'lambda' in Kλ is deliberately spartan; following lambda calculus in defining an abstraction that accepts only one argument. let is strictly otiose being definable by the equation.

(let X Y Z) = ((lambda X Z) Y)

However this form is less natural and less familiar than the traditional local assignment and is not definable except by a macro. Note that in Shen '(lambda X X)' is legal.

eval-kl

'eval-kl' evaluates a Kλ expression. It is generally not used within applications programming. The function 'eval' is not a primitive in Kλ, but 'eval-kl' is.

'eval' in Shen applied to an an expression E returns the expression E' that results from evaluating the expression E'' where E'' results from E by the replacement of all the square brackets in E' by round ones. Thus '(eval [+ 1 2])' evaluates to what '(+ 1 2) 'evaluates to - which is 3.

freeze and thaw

The function 'freeze' freezes the computation represented by its argument which is not evaluated. Effectively 'freeze' returns a continuation; defined by Wikipedia as "[the reification of] an instance of a computational process at a given point in the process's execution". The counterpart to 'freeze' is the function 'thaw' which unfreezes the computation and returns the evaluated result. 'thaw' is not primitive being readily defined in Kλ as

(defun thaw (F) (F))

Acknowledgements

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

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