diff options
Diffstat (limited to 'Master/texmf-dist')
16 files changed, 1324 insertions, 0 deletions
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 <hak7a3@live.jp> + +==== 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; + +<S-exp> ::= <cons> + | <int> + | <string> + | <symbol> + | <bool> + | <nil> + | <p-module> + | <skip> + | <dimen> +<cons> ::= (<S-exp>+) | (<S-exp> . <S-exp>) +<int> ::= :[TeX's integer] +<string> ::= '[TeX's tokens]' +<symbol> ::= [a control sequence] +<bool> ::= /t | /f +<nil> ::= () +<p-module>::= +{<modname>::<tokens>} +<modname> ::= [TeX's tokens] +<tokens> ::= [TeX's tokens] +<skip> ::= @[TeX's skip] +<dimen> ::= ![TeX's dimen] + +==== Functions and Others ==== +=== Special Forms === + * (\define \symbol <S-exp>) + -- Binds the evaluation result of <S-exp> to \symbol. + * (\lambda <ptn> <S-exp>) + -- Lambda abstraction. The bind pattern <ptn> has the following syntax; + <ptn> ::= <symbol> | (<symbol>*) | (<symbol>+ . <symbol>) + * (\quote <S-exp>) + -- Return <S-exp>. + * (\lispif <S-exp 1> <S-exp 2> <S-exp 3>) + -- Branch. The type of the evaluation result of <S-exp 1> must be bool. + * (\defmacro \symbol <Lambda abstraction>) + -- Define a macro. + * (\begin <S-exp>+) + -- Evaluate all arguments in a sequential order + and returns the the evaluation result of the last argument. + * (\defineM \symbol <S-exp>) + -- Binds the evaluation result of <S-exp> to \symbol + and the location which binds \symbol becomes "mutable". + * (\setB \symbol <S-exp>) + -- If location of which binds \symbol is "mutable", + the evaluation result of <S-exp> is stored in the location. + +=== Evaluation === + * (\eval <S-exp>) + -- Evaluate <S-exp> in the current environment. + * (\apply <func> <list>) + -- Evaluate (<func> <args>) where <list> = (<args>). + +=== Types === + * (\intQ <S-exp>) + -- If the evaluation result of <S-exp> 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 <S-exp>) + -- Return /t iff <S-exp> is a nil or a cons cell. + Otherwise, it returns /f. + * (\procedureQ <S-exp>) + -- Return /t iff <S-exp> is a closure or a function (or a macro). + * (\intTOstring <integer>) + -- convert the argument into a string. + +=== Arithmetical Functions === + * (\+ <S-exp>*) + -- Addition. + -- If, the argument is empty, it returns 0. + * (\- <S-exp>+) + -- Subtraction. + * (\* <S-exp>*) + -- Multiplication. + -- If, the argument is empty, it returns 1. + * (\/ <S-exp>+) + -- Division. + * (\mod <int 1> <int 2>) + -- Modulus. + * (\< <S-exp 1> <S-exp 2>) + -- Let n be the evaluation result of <S-exp 1> and m be that of <S-exp 2>. + If n < m, it returns /t. Otherwise, it returns /f. + +=== Manipulation of Strings === + * (\concat <string 1> <string 2>) + -- Concatenate two strings. + * (\group <string>) + -- Grouping. + -- If <string> is 'foo\bar{baz}', it returns '{foo\bar{baz}}'. + * (\ungroup <string>) + -- Ungrouping. + -- If <string> is '{foo\bar{baz}}', it returns 'foo\bar{baz}'. + +=== Manipulation of Cons Cells === + * (\cons <S-exp 1> <S-exp 2>) + -- Create a cons cell: the CAR of the cell is the evaluation result of + <S-exp 1> and the CDR of the cell is the evaluation result of + <S-exp 2>. + * (\car <cons>) + -- Get CAR part of the argument. + * (\cdr <cons>) + -- Get CAR part of the argument. + * (\length <list>) + -- 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 <list> <int>) + -- Get the <int>-th element of the <list>. + -- The numbering starts from 0. + +=== Logical Functions === + * (\and <bool 1> <bopl 2> ...) + * (\or <bool 1> <bopl 2> ...) + * (\not <bool>) + +=== Misc === + * (\= <S-exp 1> <S-exp 2>) + -- If the evaluation result of <S-exp 1> equals that of <S-exp 2>, + it returns /t. Otherwise, it returns /f. + * (\print <S-exp>) + -- Write the evaluation result of <S-exp> as LISP on TeX form. + * (\texprint <S-exp>) + -- Write the evaluation result of <S-exp> as useful form in TeX. + * (\immediatewrite) + -- Flush the output buffer immediately. + -- It may brake the evaluation routine. + * (\message <str>) + -- Write <str> to console. + * (\map <proc> <list 1> <list 2> ...) + -- Mapping function like Scheme's map. + * (\let <bindings> <body>) + -- Let bindings. + * (\letM <bindings> <body>) + -- Let bindings (mutable). + +==== Fixed Point Numbers ==== + * +{fpnum::<fixed point number>} + -- Create an fixed point number. + * (\fpplus <S-exp>*) + -- Addition. + -- If, the argument is empty, it returns 0.0. + * (\fpmunus <S-exp>+) + -- Subtraction. + * (\fpmul <S-exp>*) + -- Multiplication. + -- If, the argument is empty, it returns 1.0. + * (\fplt <S-exp 1> <S-exp 2>) + -- Let n be the evaluation result of <S-exp 1> and m be that of <S-exp 2>. + 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 Binary files differnew file mode 100644 index 00000000000..bef54e029ca --- /dev/null +++ b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fact.pdf 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 Binary files differnew file mode 100644 index 00000000000..fc227eccc5d --- /dev/null +++ b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf 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 Binary files differnew file mode 100644 index 00000000000..482cb62993b --- /dev/null +++ b/Master/texmf-dist/doc/latex/lisp-on-tex/examples/rocket.pdf 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 diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-arith.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-arith.sty new file mode 100644 index 00000000000..fc962e950f8 --- /dev/null +++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-arith.sty @@ -0,0 +1,78 @@ +\newcount\@temp@inti +\newcount\@temp@intii +\addassoc\@globalenv\+{\@tlabel@func{\@temp@inti0\relax\@arith@plus}} +\def\@arith@plus#1#2#3{% + \ifx#2\relax + \let\@next@plus\@@arith@pm@fin + \else\ifx#2\@tlabel@int + \advance\@temp@inti#3\relax + \let\@next@plus\@arith@plus + \else + \errmessage{LISP on TeX [integer plus]: Invalid argument}% + \fi\fi\@next@plus#1} + +\addassoc\@globalenv\*{\@tlabel@func{\@temp@inti1\relax\@arith@mul}} +\def\@arith@mul#1#2#3{% + \ifx#2\relax + \let\@next@mul\@@arith@pm@fin + \else\ifx#2\@tlabel@int + \multiply\@temp@inti#3\relax + \let\@next@mul\@arith@mul + \fi\fi\@next@mul#1} + +\def\@@arith@pm@fin#1{\expandafter\gdef + \expandafter#1\expandafter{% + \expandafter\@tlabel@int\expandafter{\the\@temp@inti}}} + +\addassoc\@globalenv\-{\@tlabel@func{\@arith@minus}} +\def\@arith@minus#1#2#3#4#5{% + \@temp@inti#3\relax + \ifx#4\relax + \multiply\@temp@inti-1\relax + \let\@next@minus\@@arith@pm@fin + \else\ifx#4\@tlabel@int + \let\@next@minus\@@arith@minus + \fi\fi\@next@minus#1#4{#5}} + +\def\@@arith@minus#1#2#3{% + \ifx#2\relax + \let\@next@minus\@@arith@pm@fin + \else\ifx#2\@tlabel@int + \@temp@intii#3\relax % #3 < 0 + \advance\@temp@inti-\@temp@intii\relax + \let\@next@minus\@@arith@minus + \fi\fi\@next@minus#1} + + +\addassoc\@globalenv\/{\@tlabel@func{\@arith@div}} +\def\@arith@div#1#2#3#4#5{% + \@temp@inti#3\relax + \ifx#4\relax + \@temp@intii\@temp@inti\relax + \@temp@inti1\relax + \divide\@temp@inti\@temp@intii\relax + \let\@next@div\@@arith@pm@fin + \else\ifx#4\@tlabel@int + \let\@next@div\@@arith@div + \fi\fi\@next@div#1#4{#5}} + +\def\@@arith@div#1#2#3{% + \ifx#2\relax + \let\@next@div\@@arith@pm@fin + \else\ifx#2\@tlabel@int + \divide\@temp@inti#3\relax + \let\@next@div\@@arith@div + \fi\fi\@next@div#1} + +\addassoc\@globalenv\mod{\@tlabel@func{\@arith@mod}} +\def\@arith@mod#1\@tlabel@int#2\@tlabel@int#3{% + \@temp@intii#2\relax + \divide\@temp@intii#3\relax + \multiply\@temp@intii#3\relax + \@temp@inti#2\relax + \advance\@temp@inti-\@temp@intii + \@@arith@pm@fin#1} + +\addassoc\@globalenv\<{\@tlabel@func{\@arith@lt}} +\def\@arith@lt#1\@tlabel@int#2\@tlabel@int#3{% + \ifnum#2<#3 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-latexutil.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-latexutil.sty new file mode 100644 index 00000000000..633e5cd13d5 --- /dev/null +++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-latexutil.sty @@ -0,0 +1,15 @@ +%% READ_LaTeX_Counter : string -> int +%% (\readLaTeXCounter str) -> i +%% where i = \the\c@str +\addassoc\@globalenv\readLaTeXCounter{\@tlabel@func{\@tex@read@latex@counter}} +\def\@tex@read@latex@counter#1#2#3{% + \expandafter\expandafter\expandafter\gdef + \expandafter\expandafter\expandafter#1% + \expandafter\expandafter\expandafter{% + \expandafter\expandafter\expandafter\@tlabel@int + \expandafter\expandafter\expandafter{% + \expandafter\the\csname c@#3\endcsname}}} + +\addassoc\@globalenv\message{\@tlabel@func{\@tex@lisp@message}} +\def\@tex@lisp@message#1\@tlabel@string#2{% + \gdef#1{\@tlabel@nil{}}\message{^^J#2^^J}}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-mod-fpnum.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-mod-fpnum.sty new file mode 100644 index 00000000000..54af9aa33dd --- /dev/null +++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-mod-fpnum.sty @@ -0,0 +1,84 @@ +%%% module name :: fpnum + +\def\@mod@read@fpnum#1#2{\gdef#1{\@tlabel@fpnum{#2}}} +\def\@tlabel@fpnum{\@eval@fpnum\@apply@fpnum\@@apply@fpnum} + +\def\@eval@fpnum#1#2#3{\gdef#3{\@tlabel@fpnum{#1}}} % #1 contents, #2 environment, #3 register +\def\@apply@fpnum{\errmessage{LISP on TeX [internal apply, module fpnum] cannot apply}} +\def\@@apply@fpnum{\errmessage{LISP on TeX [function --- apply, module fpnum] cannot apply}} + +\newdimen\@tempdimeni +\newdimen\@tempdimenii + +\addassoc\@globalenv\fpnumTOstring{\@tlabel@func{\@mod@fpnum@tostring}} +\def\@mod@fpnum@tostring#1\@tlabel@fpnum#2{\gdef#1{\@tlabel@string{#2}}} + +\addassoc\@globalenv\fpplus{\@tlabel@func{\@tempdimeni0pt\relax\@mod@fpnum@plus}} +\def\@mod@fpnum@plus#1#2#3{% + \ifx#2\relax + \let\@next@fpnum@plus\@@fin@fpnum@plus + \else\ifx#2\@tlabel@fpnum + \advance\@tempdimeni#3pt\relax + \let\@next@fpnum@plus\@mod@fpnum@plus + \else + \errmessage{LISP on TeX [fpnum --- plus]: Invalid argument}% + \fi\fi\@next@fpnum@plus#1} +\def\@@fin@fpnum@plus#1{\xdef#1{\noexpand\@tlabel@fpnum{\strip@pt\@tempdimeni}}} + +\addassoc\@globalenv\fpmul{\@tlabel@func{\@tempdimeni1pt\relax\@mod@fpnum@mul}} +\def\@mod@fpnum@mul#1#2#3{% + \ifx#2\relax + \let\@next@fpnum@mul\@@fin@fpnum@mul + \else\ifx#2\@tlabel@fpnum + \@tempdimeni#3\@tempdimeni + \let\@next@fpnum@mul\@mod@fpnum@mul + \else + \errmessage{LISP on TeX [fpnum --- mul]: Invalid argument}% + \fi\fi\@next@fpnum@mul#1} +\def\@@fin@fpnum@mul#1{\xdef#1{\noexpand\@tlabel@fpnum{\strip@pt\@tempdimeni}}} + +\addassoc\@globalenv\fpminus{\@tlabel@func{\@mod@fpnum@minus}} +\def\@mod@fpnum@minus#1#2#3#4#5{% + \ifx#4\relax + \ifx#2\@tlabel@fpnum + \@tempdimenii#3pt + \@tempdimeni0pt + \advance\@tempdimeni-\@tempdimenii + \let\@next@fpnum@minus\@@fin@fpnum@minus + \else + \errmessage{LISP on TeX [fpnum --- minus]: Invalid argument}% + \fi + \else\ifx#4\@tlabel@fpnum + \ifx#2\@tlabel@fpnum + \@tempdimeni#3pt + \let\@next@fpnum@minus\@@next@fpnum@minus + \else + \errmessage{LISP on TeX [fpnum --- minus]: Invalid argument}% + \fi + \else + \errmessage{LISP on TeX [fpnum --- minus]: Invalid argument}% + \fi\fi + \@next@fpnum@minus#1#4{#5}} +\def\@@fin@fpnum@minus#1{\xdef#1{\noexpand\@tlabel@fpnum{\strip@pt\@tempdimeni}}} +\def\@@next@fpnum@minus#1#2#3{% + \ifx#2\relax + \let\@next@fpnum@minus\@@fin@fpnum@minus + \else\ifx#2\@tlabel@fpnum + \@tempdimenii#3pt + \advance\@tempdimeni-\@tempdimenii + \let\@next@fpnum@minus\@@next@fpnum@minus + \else + \errmessage{LISP on TeX [fpnum --- minus]: Invalid argument}% + \fi\fi + \@next@fpnum@minus#1} + +\addassoc\@globalenv\fplt{\@tlabel@func{\@mod@fpnum@lt}} +\def\@mod@fpnum@lt#1\@tlabel@fpnum#2\@tlabel@fpnum#3{% + \ifdim#2pt<#3pt + \gdef#1{\@tlabel@bool{t}}% + \else + \gdef#1{\@tlabel@bool{f}}% + \fi +} + + diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-on-tex.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-on-tex.sty new file mode 100644 index 00000000000..e9a06ad2a55 --- /dev/null +++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-on-tex.sty @@ -0,0 +1,437 @@ +%% +%% This is file `lisp.sty'. +%% +%% License: Modified BSD - see LICENSE file +%% +%% input buffer and read function + + +%%=========================================== +%% Macros for Input Programs +%%=========================================== + +%%=========================================== +%% Public Field +%%=========================================== +%% \setinputbuffer : Set the input +\def\setinputbuffer#1{\gdef\@read@buffer{#1}} +%% \readchar : Read a letter from the input +\def\readchar{% + \ifx\@eof\@read@buffer + \gdef\@currentread{\@@eof}% + \else + \expandafter\@car@buffer\@read@buffer\relax + \fi} +%% \unreadchar : Unread a letter from the input +\def\unreadchar{% + \ifx\@eof\@currentread\else + \expandafter\@unreadchar\@currentread + \gdef\@currentread{}\fi} + +%%=========================================== +%% Private Field +%%=========================================== +\def\@dummy{\@@dummy} +\def\@read@buffer{} % The input +\def\@currentread{} % The front letter +\def\@eof{\@@eof} % EOF + +\def\@car@buffer#1#2\relax{\gdef\@currentread{#1}\gdef\@read@buffer{#2}} +\def\@unreadchar#1{% + \expandafter\gdef + \expandafter\@read@buffer + \expandafter{\expandafter#1\@read@buffer}} + +%% assoc \cs -> value +% constructor +\def\makeassoc#1{\def#1{}} +% add member +\def\addassoc#1#2#3{%#1(assoc),#2(\cs),#3(value) +\gdef\@temp@add{#3}% +\expandafter\expandafter\expandafter\gdef\expandafter\expandafter +\expandafter#1\expandafter\expandafter\expandafter{% +\expandafter\expandafter\expandafter#2\expandafter\expandafter\expandafter{\expandafter\@temp@add\expandafter}#1}} +% remove member. It cause error if there is no member +\def\rmassoc#1#2{% #1(assoc), #2(\cs) +\def\@rmassoc##1#2##2##3\relax{##1##3}% +\expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\@rmassoc#1\relax}} +% exist? +\def\ifmemassoc#1#2{% +\expandafter\@ifmemassoc\expandafter#2#1\relax} +\def\@ifmemassoc#1#2\relax{\ifx\@dummy#2\@dummy\let\@next\@iffalse\else\def\@next{\@@ifmemassoc#1#2\relax}\fi\@next} +\def\@@ifmemassoc#1#2#3#4\relax{% +\begingroup\def#1{\@@target}% +\ifx#1#2\endgroup\let\@next\@iftrue\else\endgroup\def\@next{\@ifmemassoc#1#4\relax}\fi\@next} +\def\@iffalse{\iffalse} +\def\@iftrue{\iftrue} +% get It cause error if there is no member +\def\getassoc#1#2#3{% +\def\@getassoc##1#2##2##3\relax{\gdef#3{##2}\relax}\expandafter\@getassoc#1\relax} +% show +\def\showassoc#1{\expandafter\@showassoc#1\relax} +\def\@showassoc#1\relax{\ifx\@dummy#1\@dummy +\let\@next\relax\else\def\@next{\@@showassoc#1\relax}\fi\@next} +\def\@@showassoc#1#2#3\relax{\string#1:#2,\ifx\@dummy#3\@dummy\else +\@showassoc#3\relax\fi} + + +% interface +\def\@lisp@empty{} +\def\lispinterp#1{\begingroup% + \gdef\@read@buffer{#1\@@eof\@@eof}\@lispinterp} +\def\@lispinterp{% + \readchar + \ifx\@currentread\@eof + \def\@next{\endgroup}% + \else + \def\@next{% + \unreadchar + \@lispread\@lisp@input + \lispeval\@lisp@input\@lisp@result + \@lispinterp}\fi + \@next} + + +% eval +%% write buffer +\gdef\@temp@write@buffer{} +\def\@add@to@write@buffer#1#2{% + \expandafter\gdef\expandafter#1\expandafter{#1#2}} + +%% global environment +\makeassoc\@globalenv + +% implemeted functions + + +% CONS CAR CDR +\newcount\@malloc +\def\@get@car#1\@tlabel@cons#2{\@@get@car#1#2} +\def\@@get@car#1#2#3{\global\let#1#2} +\def\@get@cdr#1\@tlabel@cons#2{\@@get@cdr#1#2} +\def\@@get@cdr#1#2#3{\global\let#1#3} +\def\@make@cons#1#2#3#4#5{% + \expandafter\gdef\csname car\the\@malloc\endcsname{#2{#3}}% + \expandafter\gdef\csname cdr\the\@malloc\endcsname{#4{#5}}% + \@@make@cons#1\csname car\the\@malloc\endcsname\csname cdr\the\@malloc\endcsname + \global\advance\@malloc1\relax} +\def\@@make@cons#1{\expandafter\@@@make@cons\expandafter#1} +\def\@@@make@cons#1#2{\expandafter\@@@@make@cons\expandafter#1\expandafter#2} +\def\@@@@make@cons#1#2#3{\gdef#1{\@tlabel@cons{#2#3}}} + + +\def\@defined@datatype{symbol,string,int,bool,dimen,skip,cons,nil,func,closure,macro,envfunc,mutable} +\def\@defined@specialform{lambda,quote,define,if,defmacro,begin,mdefine,setb,@let,@mlet} +\edef\@defined@lisp@on@tex{\@defined@datatype,\@defined@specialform} + + +%%%%%MEMO +% \@tlabel@xxx -> \@eval@xxx\@apply@xxx\@@apply@xxx +% \@dummy => ; +% \@eval@xxx#1#2#3 : #1 = cont, #2 = env, #3 = reg +%%%%% +\def\@@select@eval#1#2#3{#1} +\def\@@select@apply#1#2#3{#2} +\def\@@select@@apply#1#2#3{#3} + +\def\@type@define@filed#1{\expandafter\@@type@define@filed\expandafter#1} +\def\@@type@define@filed#1#2{\expandafter\@@@type@define@filed + \expandafter#1\expandafter#2} +\def\@@@type@define@filed#1#2#3{\expandafter\@@@@type@define@field + \expandafter#1\expandafter#2\expandafter#3} +\def\@@@@type@define@field#1#2#3#4{% + \def#1##1##2##3{\gdef##3{#4{##1}}}% + \def#2{\errmessage{LISP on TeX [internal apply]: cannot apply}}% + \def#3{\errmessage{LISP on teX [function --- apply]: cannot apply}}% + \def#4{#1#2#3}} + +\@for\@type:=\@defined@lisp@on@tex\do{% + \expandafter\@type@define@filed% + \csname @eval@\@type\endcsname% + \csname @apply@\@type\endcsname% + \csname @@apply@\@type\endcsname% + \csname @tlabel@\@type\endcsname} + + +\def\lispeval#1#2{% #1 : \cs -> S-exp, #2 : target register + \gdef\@temp@write@buffer{}% + \expandafter\@eval#1{}#2% + \@temp@write@buffer} + +\def\@eval#1#2#3#4{% + \begingroup\expandafter\@@select@eval#1{#2}{#3}#4\endgroup} + +\def\@append@env@global#1#2{% + \def#2{#1}% + \expandafter\expandafter\expandafter\def + \expandafter\expandafter\expandafter#2% + \expandafter\expandafter\expandafter{\expandafter#2\@globalenv}} + +\def\@eval@symbol#1#2#3{% + \@append@env@global{#2}\@temp@env + %% \@temp@env = #2(local environment) ++ global environment + \getassoc\@temp@env#1#3% + \expandafter\@expand@if@mutable#3#3} +\def\@expand@if@mutable#1#2#3{\ifx#1\@tlabel@mutable\global\let#3#2\fi} + +\def\@eval@envcs#1#2#3#4{\expandafter\@@eval@envcs\expandafter{#1}#2{#3}#4} +\def\@@eval@envcs#1#2#3#4{\@eval#2{#3}{#1}#4} + +\def\@eval@cons#1#2#3{\@@eval@cons#1{#2}#3} +\def\@@eval@cons#1#2#3#4{% + \expandafter\@eval#1{#3}\@temp@i + \def\@temp@ii{}% init + \expandafter\@flatten@args#2\@temp@ii + \expandafter\expandafter\expandafter\@@select@apply@pre\expandafter\@temp@i\@temp@ii\@{#3}#4} +\def\@@select@apply@pre{\expandafter\@@select@apply} + +\def\@flatten@args#1#2#3{% + \ifx#1\@tlabel@cons + \let\@flatten@next\@@flatten@next + \else\ifx#1\@tlabel@nil + \let\@flatten@next\@@flatten@fin + \else + \errmessage{LISP on TeX [internal apply]: Invalid args}% + \fi\fi + \@flatten@next#2#3} + +\def\@@flatten@next#1#2#3{% + \expandafter\expandafter\expandafter\def + \expandafter\expandafter\expandafter#3% + \expandafter\expandafter\expandafter{\expandafter#3#1}% + \expandafter\@flatten@args#2#3} + +\def\@@flatten@fin#1{} + +\def\@apply@lambda#1#2#3#4#5\@#6#7{% + \def\@lambda@args{}% init + \@create@bind#2{#3}\@lambda@args % convert arg list into internal form + \expandafter\@create@closure\@lambda@args\@{#6}#4{#5}#7} +\def\@create@closure#1\@#2#3#4#5{\gdef#5{\@tlabel@closure{{#1}{#2}#3{#4}}}} + +\def\@create@bind#1#2#3{% + \ifx#1\@tlabel@symbol + \let\@create@bind@next\@@create@listarg + \else\ifx#1\@tlabel@cons + \let\@create@bind@next\@@create@normalarg + \else\ifx#1\@tlabel@nil + \let\@create@bind@next\@@create@finarg + \fi\fi\fi + \@create@bind@next#2#3} +\def\@@create@listarg#1#2{\expandafter\def\expandafter#2\expandafter{#2:#1}} +\def\@@create@normalarg#1#2#3{% + \expandafter\@@create@bind@symbol#1#3% + \expandafter\@create@bind#2#3} +\def\@@create@bind@symbol\@tlabel@symbol#1#2{\expandafter\def\expandafter#2\expandafter{#2#1}} +\def\@@create@finarg#1{\expandafter\def\expandafter#1\expandafter{#1:\@@unused}} +\def\@@unused{\@@unused} + +\def\@apply@quote#1#2#3\@#4#5{\gdef#5{#2{#3}}} + +\def\@apply@define#1\@tlabel@symbol#2#3#4\@#5#6{% + \@eval#3{#4}{#5}#6% define does NOT use local environment + \expandafter\addassoc\expandafter\@globalenv\expandafter#2\expandafter{#6}% + \gdef#6{\@tlabel@nil{}}} + +\def\@apply@mdefine#1\@tlabel@symbol#2#3#4\@#5#6{% + \@eval#3{#4}{#5}#6% mdefine does NOT use local environment + \expandafter\@mutable@allocate#6% + \expandafter\addassoc + \expandafter\@globalenv + \expandafter#2% + \expandafter{\expandafter\@tlabel@mutable + \expandafter{\csname mutable\the\@malloc\endcsname}}% + \global\advance\@malloc1\relax + \gdef#6{\@tlabel@nil{}}} +\def\@mutable@allocate#1#2{\expandafter\gdef\csname mutable\the\@malloc\endcsname{#1{#2}}} + + +\def\@apply@setb#1\@tlabel@symbol#2#3#4\@#5#6{% + \@eval#3{#4}{#5}#6% + \let\@@save#6% + \@append@env@global{#5}\@temp@env + \getassoc\@temp@env#2\@temp@i + \let#6\@@save% + \expandafter\@set@mutable\@temp@i#6% + \gdef#6{\@tlabel@nil{}}} +\def\@set@mutable\@tlabel@mutable#1#2{\global\let#1#2} + + +\def\@apply@@let#1\@tlabel@symbol#2#3#4#5#6\@#7#8{% + \@eval#3{#4}{#7}#8% + \expandafter\def\expandafter\@temp@env\expandafter{\expandafter#2\expandafter{#8}#7}% + \expandafter\gdef\expandafter\@@tco + \expandafter{\expandafter\@@eval@envcs\expandafter{\@temp@env}#5{#6}#8}% + \aftergroup\@@tco} + +\def\@apply@@mlet#1\@tlabel@symbol#2#3#4#5#6\@#7#8{% + \@eval#3{#4}{#7}#8% + \expandafter\global\expandafter\let\csname mutable\the\@malloc\endcsname#8% + \expandafter\def\expandafter#8\expandafter{\expandafter\@tlabel@mutable + \expandafter{\csname mutable\the\@malloc\endcsname}}% + \global\advance\@malloc1\relax + \expandafter\def\expandafter\@temp@env\expandafter{\expandafter#2\expandafter{#8}#7}% + \expandafter\gdef\expandafter\@@tco + \expandafter{\expandafter\@@eval@envcs\expandafter{\@temp@env}#5{#6}#8}% + \aftergroup\@@tco} + + +\def\@apply@defmacro#1\@tlabel@symbol#2#3#4\@#5#6{% + \@eval#3{#4}{#5}#6% NOT use local env! + \expandafter\@apply@defmacro@next\expandafter#2#6% + \gdef#6{\@tlabel@nil{}}} +\def\@apply@defmacro@next#1\@tlabel@closure#2{\addassoc\@globalenv#1{\@tlabel@macro{#2}}} + +\def\@apply@if#1#2#3#4#5#6#7\@#8#9{% + \@eval#2{#3}{#8}#9% + \expandafter\@apply@if@next#9#4{#5}#6{#7}{#8}#9% + \aftergroup\@@tco + } +\def\@apply@if@next\@tlabel@bool#1#2#3#4#5#6#7{% + \ifx#1t% + \gdef\@@tco{\@eval#2{#3}{#6}#7}% + \else\ifx#1f% + \gdef\@@tco{\@eval#4{#5}{#6}#7}% + \else + \errmessage{LISP on TeX [if]: Invalid boolean. It's BUG. Please report.}% + \fi\fi} + + +%% use general +\def\@apply@eval@args#1#2#3#4{% + \ifx#3\relax + \let\@@next\@@next@fin + \else + \let\@@save#1% + \@eval#3{#4}{#2}#1% + \expandafter\expandafter\expandafter\def + \expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{% + \expandafter\@@save#1}% + \let\@@next\@apply@eval@args + \fi\@@next#1{#2}} +\def\@@next@fin#1#2{} + +\def\@apply@func#1#2\@#3#4{% + \def\@temp@i{}% + \@apply@eval@args\@temp@i{#3}#2\relax\relax + \expandafter\@apply@func@next\expandafter{\@temp@i}{#1}{#3}#4} +\def\@apply@func@next#1#2#3#4{\@@apply@func{#2}#1\@{#3}#4} + +\def\@@apply@func#1#2\@#3#4{\gdef\@@tco{#1#4#2\relax\relax}\aftergroup\@@tco} + + +\def\@apply@envfunc#1#2\@#3#4{% + \def\@temp@i{}% + \@apply@eval@args\@temp@i{#3}#2\relax\relax + \expandafter\@apply@envfunc@next\expandafter{\@temp@i}{#1}{#3}#4} +\def\@apply@envfunc@next#1#2#3#4{\@@apply@envfunc{#2}#1\@{#3}#4} + +\def\@@apply@envfunc#1#2\@#3#4{\gdef\@@tco{#1#4{#3}#2\relax\relax}\aftergroup\@@tco} + + +\def\@apply@closure#1#2\@#3#4{% + \def\@temp@i{}% + \@apply@eval@args\@temp@i{#3}#2\relax\relax + \expandafter\@apply@closure@next\expandafter{\@temp@i}{#1}{#3}#4} +\def\@apply@closure@next#1#2#3#4{\@@apply@closure{#2}#1\@{#3}#4} + +\def\@@apply@closure#1#2\@#3#4{\@@apply@closure@next#1#2\@#4} +\def\@@apply@closure@next#1#2#3#4#5\@#6{% + \def\@temp@env{}% + \@@apply@create@env\@temp@env#1#5\relax\relax + \expandafter\gdef\expandafter\@@tco\expandafter{% + \expandafter\@@eval@envcs\expandafter{\@temp@env#2}#3{#4}#6}% + \aftergroup\@@tco} + +\def\@@apply@create@env#1#2:#3#4#5{% + \ifx!#2!% if #2 is empty + \let\@@next@args@\@empty + \ifx#3\@@unused + \let\@@next\@@apply@create@env@fin + \else + \ifx#4\relax + \let\@@next\@@apply@create@env@fin + \@@apply@modify@env#1\@tlabel@nil{}#3\@ + \else + \@@apply@create@env@phantom + \expandafter\@@apply@modify@env\expandafter#1\@@@@ph#3\@ + \expandafter\gdef\csname car\the\@malloc\endcsname{#4{#5}}% + \let\@@next\@@apply@create@env@cdr + \fi + \fi + \else + \@@apply@modify@env#1#4{#5}#2\@ + \@@next@args#2\@ + \let\@@next\@@apply@create@env + \fi\expandafter\@@next\expandafter#1\@@next@args@:#3} + +\def\@@apply@create@env@cdr#1:#2{\@@@apply@create@env@cdr} +\def\@@@apply@create@env@cdr#1#2{% + \ifx#1\relax + \expandafter\gdef\csname cdr\the\@malloc\endcsname{\@tlabel@nil{}}% + \global\advance\@malloc1\relax + \let\@@next\relax + \else + \global\advance\@malloc1\relax + \@@apply@create@env@phantom + \global\advance\@malloc-1\relax + \expandafter\@@set@cdr\@@@@ph + \global\advance\@malloc1\relax + \expandafter\gdef\csname car\the\@malloc\endcsname{#1{#2}}% + \let\@@next\@@@apply@create@env@cdr + \fi\@@next} + +\def\@@set@cdr#1#2{\expandafter\gdef\csname cdr\the\@malloc\endcsname{#1{#2}}} +\def\@@apply@create@env@phantom{% + \expandafter\@@@apply@ph\csname car\the\@malloc\endcsname\csname cdr\the\@malloc\endcsname} +\def\@@@apply@ph#1{\expandafter\@@@@apply@ph\expandafter#1} +\def\@@@@apply@ph#1#2{\def\@@@@ph{\@tlabel@cons{#1#2}}} +\def\@@apply@create@env@fin#1:#2{} +\def\@@apply@modify@env#1#2#3#4#5\@{% + \ifx#2\relax + \errmessage{LISP on TeX [apply --- closure]: too few args}% + \else + \expandafter\def\expandafter#1\expandafter{#1#4{#2{#3}}}% + \fi} +\def\@@next@args#1#2\@{\def\@@next@args@{#2}} + + +\def\@@apply@macro#1#2\@#3#4{\@@apply@macro@next#1#2\@{#3}#4} +\def\@@apply@macro@next#1#2#3#4#5\@#6#7{% + \def\@temp@env{}% + \@@apply@create@env\@temp@env#1#5\relax\relax + \expandafter\gdef\expandafter\@@tco\expandafter{% + \expandafter\@@eval@envcs\expandafter{\@temp@env#2}#3{#4}#7% + \expandafter\@eval#7{#6}#7}% + \aftergroup\@@tco} +\let\@apply@macro\@@apply@macro + + + +\def\@apply@begin#1#2\@#3#4{% + \@apply@begin@next#4{#3}#2\relax\relax} +\def\@apply@begin@next#1#2#3#4#5#6{% + \ifx#5\relax + \gdef\@@tco{\@eval#3{#4}{#2}#1}% + \aftergroup\@@tco + \let\@@next\relax + \else + \@eval#3{#4}{#2}#1% + \def\@@next{\@apply@begin@next#1{#2}#5{#6}}% + \fi\@@next} + +% reader +\input{lisp-read.sty} + +%arithmetical functions +\input{lisp-arith.sty} + +%string manipulation +\input{lisp-string.sty} + +% connection to TeX world +\input{lisp-latexutil.sty} + +\input{lisp-prim.sty} + +\input{lisp-util.sty} diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-prim.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-prim.sty new file mode 100644 index 00000000000..0bd19e52081 --- /dev/null +++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-prim.sty @@ -0,0 +1,139 @@ +%% Syntax functions +\addassoc\@globalenv\quote{\@tlabel@quote{}}% +\addassoc\@globalenv\lambda{\@tlabel@lambda{}} +\addassoc\@globalenv\define{\@tlabel@define{}} +\addassoc\@globalenv\lispif{\@tlabel@if{}} +\addassoc\@globalenv\defmacro{\@tlabel@defmacro{}} +\addassoc\@globalenv\begin{\@tlabel@begin{}} +\addassoc\@globalenv\defineM{\@tlabel@mdefine{}} +\addassoc\@globalenv\setB{\@tlabel@setb{}} +\addassoc\@globalenv\@let{\@tlabel@@let{}} +\addassoc\@globalenv\@mlet{\@tlabel@@mlet{}} + + + +\addassoc\@globalenv\car{\@tlabel@func{\@get@car}} +\addassoc\@globalenv\cdr{\@tlabel@func{\@get@cdr}} +\addassoc\@globalenv\cons{\@tlabel@func{\@make@cons}} + +\newcount\@temp@count +\addassoc\@globalenv\length{\@temp@count0\relax\@tlabel@func{\@lisp@length}} +\def\@lisp@length#1#2#3{% + \ifx#2\@tlabel@nil + \expandafter\gdef\expandafter#1% + \expandafter{\expandafter\@tlabel@int\expandafter{\the\@temp@count}}% + \let\@length@next\@length@gobble + \else\ifx#2\@tlabel@cons + \advance\@temp@count1\relax + \let\@length@next\@@lisp@length + \else + \errmessage{LISP on TeX [function--length]: The Argument must be a LIST}% + \fi\fi\@length@next#3} +\def\@length@gobble#1{} +\def\@@lisp@length#1#2#3{\expandafter\@lisp@length#3} + +%equality +\addassoc\@globalenv\={\@tlabel@func{\@lisp@equal}} +\def\@lisp@equal#1#2#3#4#5{% + \gdef#1{\@tlabel@bool{f}}% + \ifx#2#4% + \def\@@temp@eqchecki{#3}% + \def\@@temp@eqcheckii{#5}% + \ifx\@@temp@eqchecki\@@temp@eqcheckii\gdef#1{\@tlabel@bool{t}}\fi + \fi} + +% printing function +\addassoc\@globalenv\print{\@tlabel@func{\@tex@print}} +\def\@tex@print#1{\gdef#1{\@tlabel@nil{}}\@tex@print@} +\def\@tex@print@#1#2{% + \ifx#1\@tlabel@int + \@add@to@write@buffer\@temp@write@buffer{:#2}% + \else\ifx#1\@tlabel@symbol + \@add@to@write@buffer\@temp@write@buffer{\string#2}% + \else\ifx#1\@tlabel@string + \@add@to@write@buffer\@temp@write@buffer{'#2'}% + \else\ifx#1\@tlabel@bool + \@add@to@write@buffer\@temp@write@buffer{/#2}% + \else\ifx#1\@tlabel@dimen + \@add@to@write@buffer\@temp@write@buffer{!#2}% + \else\ifx#1\@tlabel@skip + \@add@to@write@buffer\@temp@write@buffer{@#2}% + \else\ifx#1\@tlabel@nil + \@add@to@write@buffer\@temp@write@buffer{()}% + \else\ifx#1\@tlabel@cons + \@add@to@write@buffer\@temp@write@buffer{(}% + \@tex@print@cell#2% + \else + \@add@to@write@buffer\@temp@write@buffer{[INNER]}% + \fi\fi\fi\fi\fi\fi\fi\fi} +\def\@tex@print@cell#1#2{% + \expandafter\@tex@print@#1% + \expandafter\@tex@print@cdr#2} +\def\@tex@print@cdr#1#2{% + \ifx#1\@tlabel@cons + \@add@to@write@buffer\@temp@write@buffer{ }% + \@tex@print@cell#2% + \else\ifx#1\@tlabel@nil + \@add@to@write@buffer\@temp@write@buffer{)}% + \else + \@add@to@write@buffer\@temp@write@buffer{.}% + \@tex@print@#1{#2}% + \@add@to@write@buffer\@temp@write@buffer{)}% + \fi\fi} + + + +\addassoc\@globalenv\texprint{\@tlabel@func{\@tex@texprint}} +\def\@tex@texprint#1#2#3{% + \gdef#1{\@tlabel@nil{}}\@@tex@texprint#2{#3}} +\def\@@tex@texprint#1#2{% + \ifx#1\@tlabel@string + \@add@to@write@buffer\@temp@write@buffer{#2}% + \else\ifx#1\@tlabel@int + \@add@to@write@buffer\@temp@write@buffer{#2}% + \else + \@add@to@write@buffer\@temp@write@buffer{INNER TOKEN}% + \fi\fi} + +\addassoc\@globalenv\stdprint{\@tlabel@func{\@tex@stdprint}} +\def\@tex@stdprint#1#2#3{% + \gdef#1{\@tlabel@nil{}}\@@tex@stdprint#2{#3}} +\def\@@tex@stdprint#1#2{% + \ifx#1\@tlabel@string + \message{#2}% + \else\ifx#1\@tlabel@int + \message{#2}% + \else + \message{INNER TOKEN}% + \fi\fi} + +% Type predicates +\def\@type@pred@add#1{\expandafter\@@type@pred@add\expandafter#1} +\def\@@type@pred@add#1#2{\addassoc\@globalenv#1{\@tlabel@func{#2}}} +\def\@type@pred@define#1{\expandafter\@@type@pred@define\expandafter#1} +\def\@@type@pred@define#1#2{% + \def#1##1##2##3{\ifx##2#2\gdef##1{\@tlabel@bool{t}}\else\gdef##1{\@tlabel@bool{f}}\fi}} + +\def\@type@addassoc{\addassoc\@globalenv} +\@for\@type:=\@defined@datatype\do{% + \expandafter\@type@pred@add\csname\@type Q\endcsname\csname @type@\@type\endcsname + \expandafter\@type@pred@define\csname @type@\@type\endcsname\csname @tlabel@\@type\endcsname} + +\addassoc\@globalenv\pairQ{\@tlabel@func{\@type@cons}} +\addassoc\@globalenv\booleanQ{\@tlabel@func{\@type@bool}} + +% eval , apply +\addassoc\@globalenv\eval{\@tlabel@envfunc{\@extern@eval}} +\def\@extern@eval#1#2#3#4{\@eval#3{#4}{#2}#1} +\addassoc\@globalenv\apply{\@tlabel@envfunc{\@extern@apply}} +\def\@extern@apply#1#2#3#4#5#6{% reg, env, labelfun, contfun, labellist, contlist + \def\@lisp@apply@temp{}% init + \@flatten@args#5{#6}\@lisp@apply@temp + \expandafter\@extern@apply@next\expandafter{\@lisp@apply@temp}#3{#4}{#2}#1} +\def\@extern@apply@next#1#2#3#4#5{% arglist-flatten, labelfun, contfun env, reg + {\expandafter\@@select@@apply#2{#3}#1\@{#4}#5}} + +% values +\addassoc\@globalenv\values{\@tlabel@func{\@lisp@multivalues}} +\def\@lisp@multivalues#1#2\relax{\gdef#1{#2}} + diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty new file mode 100644 index 00000000000..a64512ff91c --- /dev/null +++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty @@ -0,0 +1,83 @@ +\def\lispread#1#2{\gdef\@read@buffer{#2\@@eof\@@eof}\@lispread#1} +\def\@lispread#1{% +\begingroup + \readchar + \if(\expandafter\noexpand\@currentread + \readchar + \if\expandafter\noexpand\@currentread)% + \gdef#1{\@tlabel@nil{}}% + \else + \unreadchar + \@lispread\@temp@i + \readchar + \if.\expandafter\noexpand\@currentread + \let\@save@temp\@temp@i + \@lispread\@temp@ii + \let\@temp@i\@save@temp + \readchar + \if)\expandafter\noexpand\@currentread + \expandafter\expandafter\expandafter\@make@cons + \expandafter\expandafter\expandafter#1% + \expandafter\@temp@i\@temp@ii + \else + \errmessage{LISP on TeX [Parse] :CANNOT FIND )}% + \fi + \else\if)\expandafter\noexpand\@currentread + \expandafter\@make@cons\expandafter#1\@temp@i\@tlabel@nil{}% + \else + \unreadchar + \expandafter\gdef + \expandafter\@read@buffer + \expandafter{% + \expandafter(\@read@buffer}% + \let\@save@temp\@temp@i + \@lispread\@temp@ii + \let\@temp@i\@save@temp + \expandafter\expandafter\expandafter\@make@cons + \expandafter\expandafter\expandafter#1% + \expandafter\@temp@i\@temp@ii + \fi\fi + \fi + \else\ifcat\relax\expandafter\noexpand\@currentread + \expandafter\gdef\expandafter#1\expandafter{% + \expandafter\@tlabel@symbol\expandafter{\@currentread}}% + \else\if'\expandafter\noexpand\@currentread + \expandafter\@read@string\expandafter#1\expandafter\@lisp@empty\@read@buffer\@@end + \else\if/\expandafter\noexpand\@currentread + \readchar + \xdef#1{\noexpand\@tlabel@bool{\@currentread}}% + \else\if:\expandafter\noexpand\@currentread + \expandafter\@read@num\expandafter#1\@read@buffer + \else\if!\expandafter\noexpand\@currentread + \expandafter\@read@dimen\expandafter#1\@read@buffer + \else\if @\expandafter\noexpand\@currentread + \expandafter\@read@skip\expandafter#1\@read@buffer + \else\if +\expandafter\noexpand\@currentread % parser module + \readchar + \expandafter\@read@module\expandafter#1\@currentread\@@end + \fi\fi\fi\fi\fi\fi\fi\fi +\endgroup} + +\newcount\@temp@read@cnt +\def\@read@num#1#2\@@eof\@@eof{% + \afterassignment\@@read@num\@temp@read@cnt#2\@@end + \expandafter\gdef + \expandafter#1% + \expandafter{\expandafter\@tlabel@int\expandafter{\the\@temp@read@cnt}}} +\def\@@read@num#1\@@end{\gdef\@read@buffer{#1\@@eof\@@eof}} + +\def\@read@dimen#1#2\@@eof\@@eof{\afterassignment\@@read@dimen\dimen@#2\@@end +\expandafter\gdef\expandafter#1\expandafter{\expandafter\@tlabel@dimen\expandafter{\the\dimen@}}} +\let\@@read@dimen\@@read@num + +\def\@read@skip#1#2\@@eof\@@eof{\afterassignment\@@read@skip\skip@#2\@@end +\expandafter\gdef\expandafter#1\expandafter{\expandafter\@tlabel@skip\expandafter{\the\skip@}}} +\let\@@read@skip\@@read@num + +\def\@read@string#1#2'#3\@@end{% + \expandafter\gdef\expandafter#1% + \expandafter{\expandafter\@tlabel@string\expandafter{#2}}% expand \@lisp@empty + \gdef\@read@buffer{#3}}% I don't consider that #3 is single grouped tokens. In LISP on TeX, it never happen. + +\def\@read@module#1#2::#3\@@end{% #1 : register, #2 : module name (MUST unique), #3 : parse target + \csname @mod@read@#2\endcsname#1{#3}} diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-string.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-string.sty new file mode 100644 index 00000000000..7d7c24b7301 --- /dev/null +++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-string.sty @@ -0,0 +1,64 @@ +%% CONCAT : string -> string -> string +%% (\concat str1 str2) => str1 ++ str2 +\addassoc\@globalenv\concat{\@tlabel@func{\def\@temp@str{}\@str@concat}} +\def\@str@concat#1#2#3{% + \let\@@next@str\relax + \ifx#2\@tlabel@string + \expandafter\def + \expandafter\@temp@str + \expandafter{\@temp@str#3}% + \let\@@next@str\@str@concat + \else\ifx#2\relax + \let\@@next@str\@str@fin + \else + \errmessage{LISP on TeX [function --- concat]:% + Arguments of concat must be strings}% + \fi\fi\@@next@str#1} +\def\@str@fin#1{% + \expandafter\gdef\expandafter#1% + \expandafter{\expandafter\@tlabel@string\expandafter{\@temp@str}}} + +%% INT2STRING : int -> string +%% (\intTOstring i) -> 'i' +\addassoc\@globalenv\intTOstring{\@tlabel@func{\@conv@intTOstr}} +\def\@conv@intTOstr#1\@tlabel@int#2{\gdef#1{\@tlabel@string{#2}}} + +%% IMMEDIATEWRITE : () -> () +%% It outputs the output buffer immediately. +%% It cause error if the buffer is imcomlete. +\addassoc\@globalenv\immediatewrite{\@tlabel@func{\@immediate@write}} +\def\@immediate@write#1{% + \gdef#1{\@tlabel@nil{}}% + \@temp@write@buffer\gdef\@temp@write@buffer{}} + +%% GROUP : string -> string +%% (\group str) -> '{str}' +\addassoc\@globalenv\group{\@tlabel@func{\@text@group}} +\def\@text@group#1#2#3{% + \ifx#2\@tlabel@string + \gdef#1{\@tlabel@string{{#3}}}% + \else + \errmessage{LISP on TeX [function --- group]:% + The argument of group must be a string.}% + \fi} + +%% UNGROUP : string -> string +%% (\group '{str}') -> 'str' +\addassoc\@globalenv\ungroup{\@tlabel@func{\@text@ungroup}} +\def\@text@ungroup#1#2#3{% + \ifx#2\@tlabel@string + \@@text@ungroup#1#3\@@end + \else + \errmessage{LISP on TeX [function --- ungroup]:% + The argument of ungroup must be a string.}% + \fi} +\def\@@text@ungroup#1#2#3\@@end{% + \ifx;#3;% + \gdef#1{\@tlabel@string{#2}}% + \else + \errmessage{LISP on TeX [function --- ungroup]:% + The argument of ungroup must be a grouped string.}% + \fi} + + + diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty new file mode 100644 index 00000000000..da4244b9f6b --- /dev/null +++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty @@ -0,0 +1,56 @@ +%%================================ +%% Definition of Utility Functions +%%================================ +\makeatletter +\lispinterp{% +(\define \listQ (\lambda (\x) (\or (\pairQ \x) (\= () \x)))) +(\define \procedureQ (\lambda (\x) + (\or (\funcQ \x) (\closureQ \x) (\envfuncQ \x) (\macroQ \x)))) +(\define \atomQ (\lambda (\x) + (\and (\not (\pairQ \x)) (\not (\= () \x)) ))) +(\define \map (\lambda (\f.\args) + (\lispif (\= () (\car \args)) () + (\let ((\cars (\@inner@map \car \args)) (\cdrs (\@inner@map \cdr \args))) + (\cons (\apply \f \cars) + (\apply \map (\cons \f \cdrs)) + ) + ) + ) + ) +) +%% @inner@map : ('a -> 'b) -> 'a list -> 'b list +(\define \@inner@map + (\lambda (\f \l) + (\lispif (\= () \l) () (\cons (\f (\car \l)) (\@inner@map \f (\cdr \l)))))) +%% not : bool -> bool +(\define \not (\lambda (\b) (\lispif \b /f /t))) +%% and : bool... -> bool +(\define \and + (\lambda \l + (\lispif (\= () \l) + /t + (\lispif (\car \l) (\apply \and (\cdr \l)) /f)))) +%% or bool... -> bool +(\define \or + (\lambda \l + (\lispif (\= () \l) + /f + (\lispif (\car \l) /t (\apply \and (\cdr \l)))))) +%% list +(\define \list (\lambda \x \x)) +%% let bindings +(\defmacro \let + (\lambda (\binds \body) + (\lispif (\= \binds ()) + \body + (\list \let (\cdr \binds) (\list \@let (\car (\car \binds)) (\car (\cdr (\car \binds))) \body))))) +(\defmacro \letM + (\lambda (\binds \body) + (\lispif (\= \binds ()) + \body + (\list \let (\cdr \binds) (\list \@mlet (\car (\car \binds)) (\car (\cdr (\car \binds))) \body))))) +% nth +(\define \nth (\lambda (\lst \n) + (\lispif (\= \n :0) (\car \lst) (\nth (\cdr \lst) (\- \n :1))))) +} +\makeatother
\ No newline at end of file |