From d472c7d8c47d5a08e34a9f4713164afc5e7a1406 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 5 Mar 2013 00:33:46 +0000 Subject: lisp-on-tex (4mar13) git-svn-id: svn://tug.org/texlive/trunk@29291 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/lisp-on-tex/LICENSE | 28 +++ Master/texmf-dist/doc/latex/lisp-on-tex/README | 229 +++++++++++++++++++++ .../doc/latex/lisp-on-tex/examples/fact.pdf | Bin 0 -> 36635 bytes .../doc/latex/lisp-on-tex/examples/fact.tex | 30 +++ .../examples/fpnummodule-mandelbrot.pdf | Bin 0 -> 32298 bytes .../examples/fpnummodule-mandelbrot.tex | 55 +++++ .../doc/latex/lisp-on-tex/examples/rocket.pdf | Bin 0 -> 30978 bytes .../doc/latex/lisp-on-tex/examples/rocket.tex | 26 +++ 8 files changed, 368 insertions(+) create mode 100644 Master/texmf-dist/doc/latex/lisp-on-tex/LICENSE create mode 100644 Master/texmf-dist/doc/latex/lisp-on-tex/README create mode 100644 Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.pdf create mode 100644 Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.tex create mode 100644 Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf create mode 100644 Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.tex create mode 100644 Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.pdf create mode 100644 Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.tex (limited to 'Master/texmf-dist/doc') diff --git a/Master/texmf-dist/doc/latex/lisp-on-tex/LICENSE b/Master/texmf-dist/doc/latex/lisp-on-tex/LICENSE new file mode 100644 index 00000000000..71f8691a7aa --- /dev/null +++ b/Master/texmf-dist/doc/latex/lisp-on-tex/LICENSE @@ -0,0 +1,28 @@ +LISP on TeX + +lisp-on-tex.sty, lisp-arith.sty, +lisp-latexutil.sty, lisp-prim.sty, +lisp-read.sty, lisp-string.sty, +lisp-util.sty, lisp-mod-fpnum.sty, +fact.tex, rocket.tex, fpnummodule-mandelbrot.tex + +Copyright (c) 2012 2013, HAKUTA Shizuya + All rights reserved. + + +Redistribution and use in source and binary forms, +with or without modification, are permitted provided +that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +-- + Copyright 1993 1994 1995 1996 1997 1998 1999 + The LaTeX3 Project and any individual authors listed elsewhere + in this file. diff --git a/Master/texmf-dist/doc/latex/lisp-on-tex/README b/Master/texmf-dist/doc/latex/lisp-on-tex/README new file mode 100644 index 00000000000..336bb425c31 --- /dev/null +++ b/Master/texmf-dist/doc/latex/lisp-on-tex/README @@ -0,0 +1,229 @@ + +%% +%% 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. diff --git a/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.pdf b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.pdf new file mode 100644 index 00000000000..bef54e029ca Binary files /dev/null and b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.pdf differ diff --git a/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.tex b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.tex new file mode 100644 index 00000000000..39fb7eeb116 --- /dev/null +++ b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.tex @@ -0,0 +1,30 @@ +\documentclass{article} +\usepackage{lisp-on-tex} +\lispinterp{% + (\define \sq (\lambda (\n) (\* \n \n))) + (\define \fact (\lambda (\n) (\lispif (\= \n :0) :1 (\* \n (\fact (\- \n :1)))))) + } +\newcommand\sq[1]{\lispinterp{(\texprint (\sq :#1))}} +\newcommand\fact[1]{\lispinterp{(\texprint (\fact :#1))}} + +\begin{document} +\section{Factorials and Squares} + \begin{center} + \begin{tabular}{r||rr}\hline\hline + $n$ & $n!$ & $n^2$ \\ + \hline + 1 & \fact{1} & \sq{1} \\ + 2 & \fact{2} & \sq{2} \\ + 3 & \fact{3} & \sq{3} \\ + 4 & \fact{4} & \sq{4} \\ + 5 & \fact{5} & \sq{5} \\ + 6 & \fact{6} & \sq{6} \\ + 7 & \fact{7} & \sq{7} \\ + 8 & \fact{8} & \sq{8} \\ + 9 & \fact{9} & \sq{9} \\ + 10 & \fact{10} & \sq{10} \\ + 11 & \fact{11} & \sq{11} \\ + \hline + \end{tabular} + \end{center} +\end{document} \ No newline at end of file diff --git a/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf new file mode 100644 index 00000000000..fc227eccc5d Binary files /dev/null and b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf differ diff --git a/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.tex b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.tex new file mode 100644 index 00000000000..f0cf68798b5 --- /dev/null +++ b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.tex @@ -0,0 +1,55 @@ +\documentclass{article} +\usepackage[pdftex,a3paper,margin=1pt,landscape]{geometry} +\newcount\mlength +\newcount\cstate +\newdimen\mandelunit +\mandelunit=0.5pt + +\def\w{% + \ifnum\cstate=1 \global\advance\mlength1 + \else \vrule width \mlength\mandelunit height \mandelunit depth 0pt \global\mlength1 \fi + \global\cstate1} +\def\b{% + \ifnum\cstate=-1 \global\advance\mlength1 + \else \hspace*{\mlength\mandelunit}\global\mlength1 \fi + \global\cstate-1} +\def\r{% + \ifnum\cstate=1\hspace*{\mlength\mandelunit}\else\vrule width \mlength\mandelunit height \mandelunit depth 0pt \fi + \global\cstate0 \global\mlength0} + +\usepackage{lisp-on-tex} +\usepackage{lisp-mod-fpnum} +\lispinterp{% + (\define \maxloop :20) + (\define \scale +{fpnum::0.002}) + (\define \isMandell + (\lambda (\a \b \k \x \y) + (\lispif (\< \maxloop \k) /t + (\lispif (\fplt +{fpnum::4.0} (\fpplus (\fpmul \x \x) (\fpmul \y \y))) + /f + (\isMandell \a \b (\+ \k :1) + (\fpplus \a (\fpmul \x \x) (\fpminus (\fpmul \y \y))) + (\fpplus \b (\fpmul +{fpnum::2.0} \x \y))))))) + (\define \drawMandell (\lambda (\a \b) + (\begin + (\lispif (\isMandell \a \b :0 +{fpnum::0} +{fpnum::0}) + (\texprint '\b') (\texprint '\w')) + (\immediatewrite)))) + (\define \loopMandell (\lambda (\a \b) + (\lispif (\fplt \b +{fpnum::-1.0}) () + (\begin + (\drawMandell \a \b) + (\lispif (\fplt +{fpnum::0.5} \a) + (\begin + (\texprint '\r\\') + (\immediatewrite) + (\loopMandell +{fpnum::-1.5} (\fpminus \b \scale))) + (\loopMandell (\fpplus \a \scale) \b)))))) +} + +\begin{document} + \thispagestyle{empty} + \noindent + \leavevmode\baselineskip=\mandelunit + \lispinterp{(\loopMandell +{fpnum::-1.5} +{fpnum::1.0})} +\end{document} \ No newline at end of file diff --git a/Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.pdf b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.pdf new file mode 100644 index 00000000000..482cb62993b Binary files /dev/null and b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.pdf differ diff --git a/Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.tex b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.tex new file mode 100644 index 00000000000..c4ed29648fd --- /dev/null +++ b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.tex @@ -0,0 +1,26 @@ +\documentclass{article} +\usepackage{lisp-on-tex} +\lispinterp{% +%rocket body +(\define \rocket + (\letM ((\count :11)) + (\lambda () + (\begin + (\setB \count (\- \count :1)) + (\lispif (\< \count :0) + (\texprint '{\small fired...}\\') + (\lispif (\= \count :0) + (\texprint '{\Large FIRE!}\\') + (\texprint (\concat 'count ' (\intTOstring \count) '...\\')))))))) +(\define \MAX :15) +%LOOP function +(\define \loop + (\lambda (\n) + (\lispif (\= \n \MAX) + () + (\begin (\rocket) (\loop (\+ \n :1)))))) +} +\begin{document} +\noindent\lispinterp{(\loop :0)} +Test done. +\end{document} \ No newline at end of file -- cgit v1.2.3