diff options
author | Karl Berry <karl@freefriends.org> | 2013-03-05 00:33:46 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-03-05 00:33:46 +0000 |
commit | d472c7d8c47d5a08e34a9f4713164afc5e7a1406 (patch) | |
tree | 4249b1eff690be906945d15b1e39e33037b1abdc /Master/texmf-dist/tex/latex/lisp-on-tex | |
parent | 0d0778a39975e8293bde2267504f53bd9d3610a6 (diff) |
lisp-on-tex (4mar13)
git-svn-id: svn://tug.org/texlive/trunk@29291 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/lisp-on-tex')
8 files changed, 956 insertions, 0 deletions
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 |