ShenDoc 30



Reader Macros

The Shen reader sits on top of the primitive bytes stream reader and reads from either a file (using 'open') or the input stream. The reader is programmable just as in Qi II, but uses the 'defmacro' construction, which is actually cleaner and easier to use than the Qi II sugar function. However internally, the defmacro construction is handled using similar techniques as for sugar functions. A macro in Shen is a 1-place function that is used by the reader to parse the user input. Here for instance is a macro used for benchmarking Shen.

(defmacro exec-macro
  [exec Expr] -> [trap-error [time Expr] [/. E failed]])

The action of this macro is to macroexpand every instance of (exec Expr) as typed or loaded into the top level by the macroexpansion of (trap-error (time Expr) (/. E failed)). There is no need to include a default 'X -> X' at the bottom of a macro (as is needed in Qi II) - this is inserted automatically. Shen macros are tied into the Shen eval function (see eval below). The function 'macroexpand' applies the list of current macros to the top level of an expression.

The mode of operation of 'macroexpand' within the reader and within eval is as follows.

Within the reader: the list of macros is composed to a fixpoint on every read token t (i.e. atom or list of atoms). If the token t is changed to t' where t <> t', the process is repeated on every subterm of t'.

Within 'eval'; the list of macros is composed on every subterm (i.e. atom or list of atoms) to a fixpoint.


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