%% %% This is file `README'. %% %% License: Modified BSD - see LICENSE file. %% ===== LISP on TeX --- A LISP interpreter on TeX ====== Version 1.0 Author : HAKUTA Shizuya ==== Introduction ==== LISP on TeX is a LISP interpreter written only with TeX macros. It works as a style file of LaTeX. LISP on TeX adopts static scoping, dynamic typing, and eager evaluation. We can program easily with LISP on TeX. ==== Files ==== README : This file. -------------------------------------------------------------------------------------- LICENCE : About LICENCE. -------------------------------------------------------------------------------------- lisp-on-tex.sty : Main routine. (evaluator) -------------------------------------------------------------------------------------- lisp-prim.sty : Primitive functions. (Automatically loaded by lisp.sty) -------------------------------------------------------------------------------------- lisp-read.sty : Parser. (Automatically loaded by lisp.sty) -------------------------------------------------------------------------------------- lisp-arith.sty : Arithmetical functions. (Automatically loaded by lisp.sty) -------------------------------------------------------------------------------------- lisp-string.sty : Functions which manipulates strings. : (Automatically loaded by lisp.sty) -------------------------------------------------------------------------------------- lisp-latexutil.sty : Utility functions for LaTeX. : (Automatically loaded by lisp.sty) -------------------------------------------------------------------------------------- lisp-util.sty : Utility functions written with LISP on TeX. : (Automatically loaded by lisp.sty) -------------------------------------------------------------------------------------- lisp-mod-fpnum.sty : The module which enables us to use fixed point numbers. : See the "Fixed Point Numbers" section in this document. -------------------------------------------------------------------------------------- examples/* : Example files. See the "Examples" section. -------------------------------------------------------------------------------------- ==== Usage ==== To use LISP on TeX, write \usepackage{lisp} in the preamble of document. We can load module files using \usepackage. For example, the command \usepackage{lisp-mod-fpnum} loads the module of fixed point numbers. It the document, we can start LISP interpreter with \lispinterp. For example, \lispinterp{(\texprint :1)} outputs "1". To get more detail, please read example files. It is the better way to know about LISP on TeX. ==== Examples ==== * fact.tex -- Calculate the factorial function. * rocket.tex -- Show how to use "mutable" locations. * fpnum-mandelbrot.tex -- Calculate the mandelbrot set. -- It takes a long long time to typeset. ==== Syntax ==== The syntax of LISP on TeX is the following; ::= | | | | | | | | ::= (+) | ( . ) ::= :[TeX's integer] ::= '[TeX's tokens]' ::= [a control sequence] ::= /t | /f ::= () ::= +{::} ::= [TeX's tokens] ::= [TeX's tokens] ::= @[TeX's skip] ::= ![TeX's dimen] ==== Functions and Others ==== === Special Forms === * (\define \symbol ) -- Binds the evaluation result of to \symbol. * (\lambda ) -- Lambda abstraction. The bind pattern has the following syntax; ::= | (*) | (+ . ) * (\quote ) -- Return . * (\lispif ) -- Branch. The type of the evaluation result of must be bool. * (\defmacro \symbol ) -- Define a macro. * (\begin +) -- Evaluate all arguments in a sequential order and returns the the evaluation result of the last argument. * (\defineM \symbol ) -- Binds the evaluation result of to \symbol and the location which binds \symbol becomes "mutable". * (\setB \symbol ) -- If location of which binds \symbol is "mutable", the evaluation result of is stored in the location. === Evaluation === * (\eval ) -- Evaluate in the current environment. * (\apply ) -- Evaluate ( ) where = (). === Types === * (\intQ ) -- If the evaluation result of is an integer, it returns /t. Otherwise, it returns /f. -- Likewise, \pairQ, \booleanQ, \symbolQ, \stringQ, \dimenQ, \skipQ, \nilQ, \funcQ, \closureQ, and \macroQ are defined. * (\listQ ) -- Return /t iff is a nil or a cons cell. Otherwise, it returns /f. * (\procedureQ ) -- Return /t iff is a closure or a function (or a macro). * (\intTOstring ) -- convert the argument into a string. === Arithmetical Functions === * (\+ *) -- Addition. -- If, the argument is empty, it returns 0. * (\- +) -- Subtraction. * (\* *) -- Multiplication. -- If, the argument is empty, it returns 1. * (\/ +) -- Division. * (\mod ) -- Modulus. * (\< ) -- Let n be the evaluation result of and m be that of . If n < m, it returns /t. Otherwise, it returns /f. === Manipulation of Strings === * (\concat ) -- Concatenate two strings. * (\group ) -- Grouping. -- If is 'foo\bar{baz}', it returns '{foo\bar{baz}}'. * (\ungroup ) -- Ungrouping. -- If is '{foo\bar{baz}}', it returns 'foo\bar{baz}'. === Manipulation of Cons Cells === * (\cons ) -- Create a cons cell: the CAR of the cell is the evaluation result of and the CDR of the cell is the evaluation result of . * (\car ) -- Get CAR part of the argument. * (\cdr ) -- Get CAR part of the argument. * (\length ) -- If the argument is "list", count the length of the argument. -- We define the term "list" as following; - The value nil. - A cons cell whose CDR is "list". * (\nth ) -- Get the -th element of the . -- The numbering starts from 0. === Logical Functions === * (\and ...) * (\or ...) * (\not ) === Misc === * (\= ) -- If the evaluation result of equals that of , it returns /t. Otherwise, it returns /f. * (\print ) -- Write the evaluation result of as LISP on TeX form. * (\texprint ) -- Write the evaluation result of as useful form in TeX. * (\immediatewrite) -- Flush the output buffer immediately. -- It may brake the evaluation routine. * (\message ) -- Write to console. * (\map ...) -- Mapping function like Scheme's map. * (\let ) -- Let bindings. * (\letM ) -- Let bindings (mutable). ==== Fixed Point Numbers ==== * +{fpnum::} -- Create an fixed point number. * (\fpplus *) -- Addition. -- If, the argument is empty, it returns 0.0. * (\fpmunus +) -- Subtraction. * (\fpmul *) -- Multiplication. -- If, the argument is empty, it returns 1.0. * (\fplt ) -- Let n be the evaluation result of and m be that of . If n < m, it returns /t. Otherwise, it returns /f.