summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/lisp-on-tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-01-04 00:18:26 +0000
committerKarl Berry <karl@freefriends.org>2014-01-04 00:18:26 +0000
commitb726d3267b3e2c379d7e1e8e4302ab8339f0bccd (patch)
treed91ecd35f96891b43e4758c04e87fe255970fbfd /Master/texmf-dist/tex/latex/lisp-on-tex
parentf5e68d092b878b0f0d86b10cbd8830cf08a153b8 (diff)
lisp-on-tex (3jan14)
git-svn-id: svn://tug.org/texlive/trunk@32561 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/lisp-on-tex')
-rw-r--r--Master/texmf-dist/tex/latex/lisp-on-tex/lisp-arith.sty5
-rw-r--r--Master/texmf-dist/tex/latex/lisp-on-tex/lisp-on-tex.sty151
-rw-r--r--Master/texmf-dist/tex/latex/lisp-on-tex/lisp-prim.sty32
-rw-r--r--Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty205
-rw-r--r--Master/texmf-dist/tex/latex/lisp-on-tex/lisp-string.sty17
-rw-r--r--Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty17
6 files changed, 289 insertions, 138 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
index fc962e950f8..7f8d51dfdf0 100644
--- a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-arith.sty
+++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-arith.sty
@@ -75,4 +75,7 @@
\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
+ \ifnum#2<#3 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi}
+\addassoc\@globalenv\>{\@tlabel@func{\@arith@gt}}
+\def\@arith@gt#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-on-tex.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-on-tex.sty
index e9a06ad2a55..95489f01602 100644
--- 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
@@ -1,5 +1,5 @@
%%
-%% This is file `lisp.sty'.
+%% This is file `lisp-on-tex.sty'.
%%
%% License: Modified BSD - see LICENSE file
%%
@@ -77,19 +77,17 @@
% interface
\def\@lisp@empty{}
-\def\lispinterp#1{\begingroup%
- \gdef\@read@buffer{#1\@@eof\@@eof}\@lispinterp}
-\def\@lispinterp{%
- \readchar
- \ifx\@currentread\@eof
- \def\@next{\endgroup}%
+\def\lispinterp#1{%
+ \@lispread\@lisp@read@eval@loop#1\@end@lispread}
+\def\@lisp@read@eval@loop#1#2{%
+ \ifx#1\@tlabel@exception
+ \let\@@next\relax
\else
- \def\@next{%
- \unreadchar
- \@lispread\@lisp@input
- \lispeval\@lisp@input\@lisp@result
- \@lispinterp}\fi
- \@next}
+ \def\@reg@tmp{#1{#2}}%
+ \def\@@next{%
+ \lispeval\@reg@tmp\@reg@tmp
+ \@lispread\@lisp@read@eval@loop}%
+ \fi\@@next}
% eval
@@ -120,8 +118,8 @@
\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}
+\def\@defined@datatype{symbol,string,int,bool,dimen,skip,cons,nil,func,closure,macro,envfunc,mutable,exception}
+\def\@defined@specialform{lambda,quote,define,if,defmacro,begin,mdefine,setb,@let,@mlet,macroexpand}
\edef\@defined@lisp@on@tex{\@defined@datatype,\@defined@specialform}
@@ -153,13 +151,34 @@
\csname @tlabel@\@type\endcsname}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% memo of fasteval branch
+% Each bound variables \var
+% is defined as TeX macro [[@lisp@env@\var]]
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\def\@lisp@expand@env@last{\@lisp@expand@env@last}
+
+\def\@lisp@expand@environment#1#2{%
+ \ifx#1\@lisp@expand@env@last
+ \let\@@next\relax
+ \else
+ \expandafter\def\csname @lisp@env@\string#1\endcsname{#2}%
+ \let\@@next\@lisp@expand@environment
+ \fi
+ \@@next}
+
\def\lispeval#1#2{% #1 : \cs -> S-exp, #2 : target register
\gdef\@temp@write@buffer{}%
- \expandafter\@eval#1{}#2%
+ \expandafter\@lisp@expand@environment\@globalenv\@lisp@expand@env@last\@lisp@expand@env@last%
+ \expandafter\@eval#1{}#2%
\@temp@write@buffer}
\def\@eval#1#2#3#4{%
- \begingroup\expandafter\@@select@eval#1{#2}{#3}#4\endgroup}
+ \begingroup
+ \@lisp@expand@environment#3\@lisp@expand@env@last\@lisp@expand@env@last
+ \expandafter\@@select@eval#1{#2}{#3}#4%
+ \endgroup}
\def\@append@env@global#1#2{%
\def#2{#1}%
@@ -167,12 +186,25 @@
\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@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\@eval@symbol#1#2#3{% #1 symbol #2 current env (ignored) #3 dist
+ \expandafter\global\expandafter\let\expandafter#3\csname @lisp@env@\string#1\endcsname
+ \ifx#3\relax % not found
+ \errmessage{LISP on TeX [evaluation of a symbol]: unbound variable...}%
+ \else
+ \expandafter\@expand@if@mutable#3#3%
+ \fi}
+\def\@expand@if@mutable#1#2#3{%
+ \let\@@next\@expand@if@mutable@next@f
+ \ifx#1\@tlabel@mutable\let\@@next\@expand@if@mutable@next@t\fi
+ \@@next{#2}{#3}}
+\def\@expand@if@mutable@next@f#1#2{}
+\def\@expand@if@mutable@next@t#1#2{\global\let#2#1}
+
\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}
@@ -288,27 +320,36 @@
\aftergroup\@@tco
}
\def\@apply@if@next\@tlabel@bool#1#2#3#4#5#6#7{%
+ \let\@@next\relax
\ifx#1t%
- \gdef\@@tco{\@eval#2{#3}{#6}#7}%
+ \let\@@next\@apply@if@next@t
\else\ifx#1f%
- \gdef\@@tco{\@eval#4{#5}{#6}#7}%
+ \let\@@next\@apply@if@next@f
\else
\errmessage{LISP on TeX [if]: Invalid boolean. It's BUG. Please report.}%
- \fi\fi}
+ \fi\fi\@@next{#1}{#2}{#3}{#4}{#5}{#6}{#7}}
+\def\@apply@if@next@t#1#2#3#4#5#6#7{\gdef\@@tco{\@eval#2{#3}{#6}#7}}
+\def\@apply@if@next@f#1#2#3#4#5#6#7{\gdef\@@tco{\@eval#4{#5}{#6}#7}}
%% use general
\def\@apply@eval@args#1#2#3#4{%
+ \let\@@next@pre\@apply@eval@args@pre@default
\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}}
+ \let\@@next@pre\@apply@eval@args@pre@i
+ \fi\@@next@pre{#1}{#2}{#3}{#4}\@@next#1{#2}}
+
+\def\@apply@eval@args@pre@default#1#2#3#4{}
+\def\@apply@eval@args@pre@i#1#2#3#4{%
+ \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}
+
\def\@@next@fin#1#2{}
\def\@apply@func#1#2\@#3#4{%
@@ -344,6 +385,7 @@
\aftergroup\@@tco}
\def\@@apply@create@env#1#2:#3#4#5{%
+ \let\@@next@pre\@@apply@create@env@pre@default
\ifx!#2!% if #2 is empty
\let\@@next@args@\@empty
\ifx#3\@@unused
@@ -353,17 +395,24 @@
\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
+ \let\@@next@pre\@@apply@create@env@pre@i
\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}
+ \let\@@next@pre\@@apply@create@env@pre@ii
+ \fi\@@next@pre{#1}{#2}{#3}{#4}{#5}\expandafter\@@next\expandafter#1\@@next@args@:#3}
+
+\def\@@apply@create@env@pre@default#1#2#3#4#5{}
+\def\@@apply@create@env@pre@i#1#2#3#4#5{%
+ \@@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}
+\def\@@apply@create@env@pre@ii#1#2#3#4#5{%
+ \@@apply@modify@env#1#4{#5}#2\@
+ \@@next@args#2\@
+ \let\@@next\@@apply@create@env}
+
\def\@@apply@create@env@cdr#1:#2{\@@@apply@create@env@cdr}
\def\@@@apply@create@env@cdr#1#2{%
@@ -395,7 +444,6 @@
\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{}%
@@ -406,6 +454,25 @@
\aftergroup\@@tco}
\let\@apply@macro\@@apply@macro
+\def\@apply@macroexpand#1#2#3\@#4#5{% cont, args, \@ env, reg
+ \let\@@apply@macro@next\@@apply@macro@next@expand@only
+ \@eval#2{#3}{#4}#5%
+ \expandafter\@eval#5{#4}#5}
+\def\@@apply@macro@next@expand@only#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@if@macro#7{#6}#7}%
+ \aftergroup\@@tco}
+\def\@eval@if@macro#1#2#3#4{%
+ \ifx#1\@tlabel@cons\@eval@if@macro@#2{#3}#4\fi}
+\def\@eval@if@macro@#1#2#3#4{%
+ \expandafter\@eval#1{#3}\@temp@i
+ \expandafter\@eval@if@macro@@\@temp@i#1#2{#3}#4}
+\def\@eval@if@macro@@#1#2#3#4#5#6{%
+ \ifx#1\@tlabel@macro\@eval\@tlabel@cons{#3#4}{#5}#6\else\gdef#6{\@tlabel@cons{#3#4}}\fi}
+
\def\@apply@begin#1#2\@#3#4{%
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
index 0bd19e52081..95432a86ef3 100644
--- a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-prim.sty
+++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-prim.sty
@@ -9,7 +9,7 @@
\addassoc\@globalenv\setB{\@tlabel@setb{}}
\addassoc\@globalenv\@let{\@tlabel@@let{}}
\addassoc\@globalenv\@mlet{\@tlabel@@mlet{}}
-
+\addassoc\@globalenv\macroexpand{\@tlabel@macroexpand{}}
\addassoc\@globalenv\car{\@tlabel@func{\@get@car}}
@@ -97,15 +97,14 @@
\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}
+ \gdef#1{\@tlabel@nil{}}%
+ \let\@save@write@buffer\@temp@write@buffer
+ \def\@temp@write@buffer{}%
+ \@tex@print@#2{#3}%
+ \toks0\expandafter{\@temp@write@buffer}%
+ \immediate\write16{\the\toks0}%
+ \let\@temp@write@buffer\@save@write@buffer}
+
% Type predicates
\def\@type@pred@add#1{\expandafter\@@type@pred@add\expandafter#1}
@@ -134,6 +133,13 @@
{\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}}
-
+%\addassoc\@globalenv\values{\@tlabel@func{\@lisp@multivalues}}
+%\def\@lisp@multivalues#1#2\relax{\gdef#1{#2}}
+
+% read
+\addassoc\@globalenv\read{\@tlabel@func{\@lisp@read@stdin}}
+\def\@lisp@read@stdin#1{%
+ \read-1 to#1%
+ \def\@lisp@read@stdin@callback##1##2{%
+ \gdef#1{##1{##2}}}%
+ \expandafter\@lispread\expandafter\@lisp@read@stdin@callback#1}
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
index a64512ff91c..e93e752521f 100644
--- a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty
+++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-read.sty
@@ -1,83 +1,128 @@
-\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}}
+%%
+%% This is file `lisp-read.sty'.
+%%
+%% License: Modified BSD - see LICENSE file
+%%
-\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
+%% End Of Input(EOI)
+\def\@end@lispread{\@@end@lispread}
-\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
+%% Reader Macro
+%% @param #1 callback function (which gets a S-exp and do something)
+%% @param #2 the first letter of the input or EOI
+%% @return #1\@tlabel@xxx{contents}
+\def\@lispread#1#2{\begingroup\@lispread@main#1#2}
-\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}}
+%% The first branch
+%% @param #1 callback function
+%% @param #2 the first letter of the input or EOI
+\def\@lispread@main#1#2{% Define \@@next, the continuation.
+ \if\noexpand#2(% [Branch 1] CONS cell or NIL
+ \def\@@next{\@lispread@cell#1}%
+ \else\ifcat\noexpand#2\relax% [Branch 2] A control sequence or a control symbol
+ \ifx#2\@end@lispread % [Branch 2-1] EOI
+ \def\@@next{\endgroup#1\@tlabel@exception{!Found End of Input!}}%
+ \else
+ \def\@@next{\@lispread@symbol#1#2}% [Branch 2-2] Symbol
+ \fi
+ \else\if\noexpand#2'% [Branch 3] String
+ \def\@@next{\@lispread@string#1}%
+ \else\if\noexpand#2/% [Branch 4] Boolean
+ \def\@@next{\@lispread@bool#1}%
+ \else\if\noexpand#2:% [Branch 5] Integer
+ \def\@@next{\@lispread@int#1}%
+ \else\if\noexpand#2!% [Branch 6] Dimension
+ \def\@@next{\@lispread@dimen#1}%
+ \else\if\noexpand#2@% [Branch 7] Skip
+ \def\@@next{\@lispread@skip#1}%
+ \else\if\noexpand#2+% [Branch 8] call a Reader Module
+ \def\@@next{\@lispread@module#1}%
+ \else % Otherwise -- parse error
+ \errmessage{LISP on teX [read]: no such type start with \noexpand#2}%
+ \fi\fi\fi\fi\fi\fi\fi\fi
+ \@@next}
+%% Symbol
+\def\@lispread@symbol#1#2{%
+ \endgroup#1\@tlabel@symbol{#2}}
+%% String
+\def\@lispread@string#1#2'{%
+ \endgroup#1\@tlabel@string{#2}}
+%% Boolean
+\def\@lispread@bool#1#2{%
+ \endgroup#1\@tlabel@bool{#2}}
+%% Reader Module
+\def\@lispread@module#1#2{%
+ \@lispread@module@main\@register@lispread@module#2\@@end
+ \endgroup
+ \expandafter#1\@register@lispread@module}
+\def\@lispread@module@main#1#2::#3\@@end{\csname @mod@read@#2\endcsname#1{#3}}
+%% Integer
+\newcount\@cnt@lispread@int
+\def\@lispread@int#1{%
+ \gdef\@lispread@int@callback{\@lispread@int@main#1}%
+ \afterassignment\@lispread@int@callback
+ \global\@cnt@lispread@int}
+\def\@lispread@int@main#1{%
+ \endgroup\expandafter#1\expandafter\@tlabel@int\expandafter{\the\@cnt@lispread@int}}
+%% Skip
+\newskip\@cnt@lispread@skip
+\def\@lispread@skip#1{%
+ \gdef\@lispread@skip@callback{\@lispread@skip@main#1}%
+ \afterassignment\@lispread@skip@callback
+ \global\@cnt@lispread@skip}
+\def\@lispread@skip@main#1{%
+ \endgroup\expandafter#1\expandafter\@tlabel@skip\expandafter{\the\@cnt@lispread@skip}}
+%% Dimen
+\newdimen\@cnt@lispread@dimen
+\def\@lispread@dimen#1{%
+ \gdef\@lispread@dimen@callback{\@lispread@dimen@main#1}%
+ \afterassignment\@lispread@dimen@callback
+ \global\@cnt@lispread@dimen}
+\def\@lispread@dimen@main#1{%
+ \endgroup\expandafter#1\expandafter\@tlabel@dimen\expandafter{\the\@cnt@lispread@dimen}}
+%% CONS cell or NIL
+\def\@lispread@cell#1#2{%
+ \if\noexpand#2)% [Branch 1] NIL
+ \def\@@next{\endgroup#1\@tlabel@nil{}}%
+ \else % Otherwise CONS cell
+ \def\@@next{\@lispread@cell@car#1#2}%
+ \fi\@@next}
+%% first part of CONS cell : read CAR
+\def\@lispread@cell@car#1{%
+ \def\@lispread@car@reg##1##2{%
+ \def\@reg@lispread@car{##1{##2}}%
+ \@lispread@cell@dot#1}%
+ \@lispread\@lispread@car@reg}
+\def\@lispread@cell@dot#1#2{%
+ \if\noexpand#2.%
+ \def\@@next{%
+ \def\@lispread@cell@fincheck####1####2{%
+ \def\@reg@lispread@cdr{####1{####2}}%
+ \@lispread@fin#1}%
+ \@lispread\@lispread@cell@fincheck}% kokonaosu
+ \else
+ \def\@@next{\@lispread@cell@cdr#1(#2}%
+ \fi\@@next}
+\def\@lispread@cell@cdr#1{%
+ \def\@lispread@cdr@reg##1##2{%
+ \expandafter\@read@malloc\expandafter\@reg@tmp\@reg@lispread@car##1{##2}%
+ \expandafter\endgroup\expandafter#1\@reg@tmp}%
+ \@lispread\@lispread@cdr@reg}
+\def\@lispread@fin#1#2{%
+ \if\noexpand#2)%
+ \def\@@next{%
+ \expandafter\expandafter\expandafter\@read@malloc
+ \expandafter\expandafter\expandafter\@reg@tmp
+ \expandafter\@reg@lispread@car\@reg@lispread@cdr
+ \expandafter\endgroup\expandafter#1\@reg@tmp}%
+ \else
+ \def\@@next{\errmessage{LISP on teX [read]: missing )}}%
+ \fi\@@next}
+\def\@read@malloc#1#2#3#4#5{%
+ \expandafter\gdef\csname car\the\@malloc\endcsname{#2{#3}}%
+ \expandafter\gdef\csname cdr\the\@malloc\endcsname{#4{#5}}%
+ \expandafter\@@read@malloc\expandafter#1\csname car\the\@malloc\endcsname\csname cdr\the\@malloc\endcsname}
+\def\@@read@malloc#1#2{\expandafter\@@@read@malloc\expandafter#1\expandafter#2}
+\def\@@@read@malloc#1#2#3{%
+ \global\advance\@malloc1
+ \def#1{\@tlabel@cons{#2#3}}} \ No newline at end of file
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
index 7d7c24b7301..87345706583 100644
--- a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-string.sty
+++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-string.sty
@@ -25,7 +25,7 @@
%% IMMEDIATEWRITE : () -> ()
%% It outputs the output buffer immediately.
-%% It cause error if the buffer is imcomlete.
+%% It cause error if the buffer is incomplete.
\addassoc\@globalenv\immediatewrite{\@tlabel@func{\@immediate@write}}
\def\@immediate@write#1{%
\gdef#1{\@tlabel@nil{}}%
@@ -60,5 +60,20 @@
The argument of ungroup must be a grouped string.}%
\fi}
+%% FGETS : () -> string
+%% (\fgets) -> read tokens from standard-in
+\addassoc\@globalenv\fgets{\@tlabel@func{\@text@fgets}}
+\def\@text@fgets#1{%
+\endlinechar=-1
+\read-1to#1%
+\expandafter\gdef\expandafter#1\expandafter{\expandafter\@tlabel@string\expandafter{#1}}}
+
+%% EXPAND : string -> string
+%% (\expand '<token>') -> '<token+>' where <token+> is expanded tokens of <token>
+\addassoc\@globalenv\expand{\@tlabel@func{\@lot@text@expand}}
+\def\@lot@text@expand#1\@tlabel@string#2{%
+ \edef\@temp@i{#2}%
+ \xdef#1{\noexpand\@tlabel@string{\@temp@i}}}
+
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
index da4244b9f6b..f263d7059cb 100644
--- a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty
+++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty
@@ -48,7 +48,22 @@
(\lambda (\binds \body)
(\lispif (\= \binds ())
\body
- (\list \let (\cdr \binds) (\list \@mlet (\car (\car \binds)) (\car (\cdr (\car \binds))) \body)))))
+ (\list \letM (\cdr \binds) (\list \@mlet (\car (\car \binds)) (\car (\cdr (\car \binds))) \body)))))
+% letrec
+(\defmacro \letrec (\lambda (\binds \body) (\list \@letrec \binds \binds \body)))
+(\defmacro \@letrec
+ (\lambda (\binds \save \body)
+ (\lispif (\= \binds ())
+ (\list \@@letrec \save \body)
+ (\list \@letrec (\cdr \binds) \save
+ (\list \begin
+ (\list \setB (\car (\car \binds)) (\car (\cdr (\car \binds))))
+ \body)))))
+(\defmacro \@@letrec
+ (\lambda (\binds \body)
+ (\lispif (\= \binds ())
+ \body
+ (\list \@@letrec (\cdr \binds) (\list \@mlet (\car (\car \binds)) () \body)))))
% nth
(\define \nth (\lambda (\lst \n)
(\lispif (\= \n :0) (\car \lst) (\nth (\cdr \lst) (\- \n :1)))))