diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/lisp-on-tex/examples |
Initial commit
Diffstat (limited to 'macros/latex/contrib/lisp-on-tex/examples')
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/div2.pdf | bin | 0 -> 11875 bytes | |||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/div2.tex | 30 | ||||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/fact.pdf | bin | 0 -> 36632 bytes | |||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/fact.tex | 30 | ||||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf | bin | 0 -> 32295 bytes | |||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/fpnummodule-mandelbrot.tex | 55 | ||||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/nqueen.pdf | bin | 0 -> 12971 bytes | |||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/nqueen.tex | 47 | ||||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/repl.tex | 12 | ||||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/rocket.pdf | bin | 0 -> 30975 bytes | |||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/rocket.tex | 26 | ||||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/showfont.pdf | bin | 0 -> 13933 bytes | |||
-rw-r--r-- | macros/latex/contrib/lisp-on-tex/examples/showfont.tex | 32 |
13 files changed, 232 insertions, 0 deletions
diff --git a/macros/latex/contrib/lisp-on-tex/examples/div2.pdf b/macros/latex/contrib/lisp-on-tex/examples/div2.pdf Binary files differnew file mode 100644 index 0000000000..6cb01f55aa --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/div2.pdf diff --git a/macros/latex/contrib/lisp-on-tex/examples/div2.tex b/macros/latex/contrib/lisp-on-tex/examples/div2.tex new file mode 100644 index 0000000000..ae2cf824ee --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/div2.tex @@ -0,0 +1,30 @@ +\documentclass{article} +%\usepackage{lisp-on-tex} +\usepackage[markGC]{lisp-on-tex} +\lispinterp { + (\define (\create \n) (\createAcc \n ())) + (\define (\createAcc \n \acc) + (\lispif (\= \n :0) \acc (\createAcc (\- \n :1) (\cons () \acc)))) + (\define \ll (\create :200)) + (\define (\divII \l) + (\lispif (\= \l ()) () (\cons (\car \l) (\divII (\cdr (\cdr \l)))))) + (\define (\test \l) (\testAcc \l :500)) % original is 300 + (\define (\testAcc \l \i) + (\lispif (\= \i :0) () + (\begin + (\lispif (\= (\length (\divII \l)) :100) + () (\texprint 'Hmm')) + (\lispif (\= (\length (\divII \l)) :100) + () (\message 'Hmm')) + (\lispif (\= (\length (\divII \l)) :100) + () (\message 'Hmm')) + (\lispif (\= (\length (\divII \l)) :100) + () (\message 'Hmm')) + (\texprint \i) + (\texprint ' ') + (\testAcc \l (\- \i :1))))) +} + +\begin{document} + \lispinterp{(\test \ll)} +\end{document}
\ No newline at end of file diff --git a/macros/latex/contrib/lisp-on-tex/examples/fact.pdf b/macros/latex/contrib/lisp-on-tex/examples/fact.pdf Binary files differnew file mode 100644 index 0000000000..5bb156ab39 --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/fact.pdf diff --git a/macros/latex/contrib/lisp-on-tex/examples/fact.tex b/macros/latex/contrib/lisp-on-tex/examples/fact.tex new file mode 100644 index 0000000000..39fb7eeb11 --- /dev/null +++ b/macros/latex/contrib/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/macros/latex/contrib/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf b/macros/latex/contrib/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf Binary files differnew file mode 100644 index 0000000000..b40e5f7c9b --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/fpnummodule-mandelbrot.pdf diff --git a/macros/latex/contrib/lisp-on-tex/examples/fpnummodule-mandelbrot.tex b/macros/latex/contrib/lisp-on-tex/examples/fpnummodule-mandelbrot.tex new file mode 100644 index 0000000000..f0cf68798b --- /dev/null +++ b/macros/latex/contrib/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/macros/latex/contrib/lisp-on-tex/examples/nqueen.pdf b/macros/latex/contrib/lisp-on-tex/examples/nqueen.pdf Binary files differnew file mode 100644 index 0000000000..c605d4212c --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/nqueen.pdf diff --git a/macros/latex/contrib/lisp-on-tex/examples/nqueen.tex b/macros/latex/contrib/lisp-on-tex/examples/nqueen.tex new file mode 100644 index 0000000000..9de2d28402 --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/nqueen.tex @@ -0,0 +1,47 @@ +\documentclass{article} +\usepackage{lisp-on-tex} +\makeatletter +\lispinterp{ + (\define \nqueen (\lambda (\n) + (\callOCC (\lambda (\c) (\nqinner \n () \c))))) + (\define \nqinner (\lambda (\n \acc \c) + (\lispif (\= (\length \acc) \n) + (\lispif (\nqcheck \acc) (\c \acc) ()) + (\nqinnernext \n \acc \c :1)))) + (\define \nqinnernext (\lambda (\n \acc \c \k) + (\lispif (\< \n \k) () + (\begin + (\nqinner \n (\cons \k \acc) \c) + (\nqinnernext \n \acc \c (\+ \k :1)))))) + (\define \seq (\lambda (\n) + (\lispif (\= \n :1) (\quote (:1)) (\cons \n (\seq (\- \n :1)))))) + (\define \nqcheck (\lambda (\lst) + (\and (\uniqueQ \lst) (\nqcheckdiag \lst)))) + (\define \nqcheckdiag (\lambda (\lst) (\nqcheckdiaginner \lst :1))) + (\define \nqcheckdiaginner (\lambda (\lst \k) + (\lispif (\< (\length \lst) \k) /t + (\lispif (\nqcheckdiagK \lst \k :1) + (\nqcheckdiaginner \lst (\+ \k :1)) /f)))) + (\define \nqcheckdiagK (\lambda (\lst \k \n) + (\lispif (\> \n (\length \lst)) /t + (\let ((\t (\nth \lst (\- \k :1))) + (\tt (\nth \lst (\- \n :1))) + (\d (\- \n \k))) + (\lispif (\and + (\not (\= \n \k)) + (\or (\= \t (\+ \tt \d)) (\= \t (\- \tt \d)) )) + /f (\nqcheckdiagK \lst \k (\+ \n :1))))))) + (\define \uniqueQ (\lambda (\list) + (\lispif (\= \list ()) /t + (\and (\not (\existQ (\car \list) (\cdr \list))) (\uniqueQ (\cdr \list)))))) + (\define \existQ (\lambda (\v \list) + (\lispif (\= \list ()) /f + (\or (\= \v (\car \list)) (\existQ \v (\cdr \list)))))) + (\define \reverse (\lambda (\l) + (\lispif (\= \l ()) () (\append (\reverse (\cdr \l)) (\car \l))))) + (\define \append (\lambda (\l \v) + (\lispif (\= \l ()) (\cons \v ()) (\cons (\car \l) (\append (\cdr \l) \v))))) +} +\begin{document} +hoge\lispinterp{(\print (\nqueen :5))}fuga +\end{document}
\ No newline at end of file diff --git a/macros/latex/contrib/lisp-on-tex/examples/repl.tex b/macros/latex/contrib/lisp-on-tex/examples/repl.tex new file mode 100644 index 0000000000..9a4d1a9bdb --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/repl.tex @@ -0,0 +1,12 @@ +\documentclass{article} +\usepackage{lisp-on-tex} +\lispinterp{% + (\define \repl (\lambda () + (\begin + (\stdprint (\eval (\read))) + (\repl)))) +} +\begin{document} + \typeout{LISP on TeX interpretor mode} + \lispinterp{(\repl)} +\end{document}
\ No newline at end of file diff --git a/macros/latex/contrib/lisp-on-tex/examples/rocket.pdf b/macros/latex/contrib/lisp-on-tex/examples/rocket.pdf Binary files differnew file mode 100644 index 0000000000..bfff99d340 --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/rocket.pdf diff --git a/macros/latex/contrib/lisp-on-tex/examples/rocket.tex b/macros/latex/contrib/lisp-on-tex/examples/rocket.tex new file mode 100644 index 0000000000..c4ed29648f --- /dev/null +++ b/macros/latex/contrib/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/macros/latex/contrib/lisp-on-tex/examples/showfont.pdf b/macros/latex/contrib/lisp-on-tex/examples/showfont.pdf Binary files differnew file mode 100644 index 0000000000..13ef7fce56 --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/showfont.pdf diff --git a/macros/latex/contrib/lisp-on-tex/examples/showfont.tex b/macros/latex/contrib/lisp-on-tex/examples/showfont.tex new file mode 100644 index 0000000000..31200d9796 --- /dev/null +++ b/macros/latex/contrib/lisp-on-tex/examples/showfont.tex @@ -0,0 +1,32 @@ +\documentclass{article} +\usepackage{lisp-on-tex} +\newcount\hoge \hoge\endlinechar +\endlinechar=-1 +\read16 to\tmp +\endlinechar=\hoge +\global\font\testfont="\tmp" +\lispinterp{ + (\define \foldl (\lambda (\func \init \list) + (\lispif (\= \list ()) + \init + (\foldl \func (\func \init (\car \list)) (\cdr \list))))) + (\define \createtoken (\lambda (\code) + (\concat '\iffontchar\testfont' (\concat (\intTOstring \code) 't\else f\fi' )))) + (\define \MAX :"30000)} +\begin{document} +\noindent +\lispinterp{ + (\letrec ((\count :0) + (\loop (\lambda () + (\lispif (\< \MAX \count) () + (\begin + (\lispif (\= 't' (\expand (\createtoken \count))) + (\texprint (\group (\concat '\testfont\char' (\intTOstring \count)))) + ()) + (\texprint '\hskip0pt plus1pt') + (\immediatewrite) + (\setB \count (\+ \count :1)) + (\loop)))))) + (\loop)) + } +\end{document}
\ No newline at end of file |