| 1 |
% Filename: lambda.sty |
| 2 |
% Author: Alan Jeffrey |
| 3 |
% Last modified: 12 Feb 1990 (license changed to LPPL: 6 Aug 2013) |
| 4 |
% |
| 5 |
% Copyright 1990-2013 Alan Jeffrey. |
| 6 |
% This file is part of the lambda-lists package. |
| 7 |
% |
| 8 |
% This work may be distributed and/or modified under the |
| 9 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 10 |
% of this license or (at your option) any later version. |
| 11 |
% The latest version of this license is in |
| 12 |
% http://www.latex-project.org/lppl.txt |
| 13 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 14 |
% version 2003/12/01 or later. |
| 15 |
% |
| 16 |
% This style provides a pile of lambda-calculus and list-handling |
| 17 |
% macros of an incredibly obtuse nature. Read lambda-lists.tex to find out |
| 18 |
% what they all do and how they do it. This \TeX\ code was formally |
| 19 |
% verified. |
| 20 |
% Alan Jeffrey, 25 Jan 1990. |
| 21 |
|
| 22 |
\def\Identity#1{#1} |
| 23 |
|
| 24 |
\def\Error% |
| 25 |
{\errmessage{Abandon verification all |
| 26 |
ye who enter here}} |
| 27 |
|
| 28 |
\def\First#1#2{#1} |
| 29 |
\def\Second#1#2{#2} |
| 30 |
|
| 31 |
\def\Compose#1#2#3{#1{#2{#3}}} |
| 32 |
|
| 33 |
\def\Twiddle#1#2#3{#1{#3}{#2}} |
| 34 |
|
| 35 |
\let\True=\First |
| 36 |
\let\False=\Second |
| 37 |
\let\Not=\Twiddle |
| 38 |
|
| 39 |
\def\And#1#2{#1{#2}\False} |
| 40 |
\def\Or#1#2{#1\True{#2}} |
| 41 |
|
| 42 |
\def\Lift#1#2#3#4{#1{#4}{#2}{#3}{#4}} |
| 43 |
|
| 44 |
\def\Lessthan#1#2{\TeXif{\ifnum#1<#2 }} |
| 45 |
|
| 46 |
\def\gobblefalse\else\gobbletrue\fi#1#2% |
| 47 |
{\fi#1} |
| 48 |
\def\gobbletrue\fi#1#2% |
| 49 |
{\fi#2} |
| 50 |
\def\TeXif#1% |
| 51 |
{#1\gobblefalse\else\gobbletrue\fi} |
| 52 |
|
| 53 |
\def\Nil#1#2{#2} |
| 54 |
\def\Cons#1#2#3#4{#3{#1}{#2}} |
| 55 |
\def\Stream#1{\Cons{#1}{\Stream{#1}}} |
| 56 |
\def\Singleton#1{\Cons{#1}\Nil} |
| 57 |
|
| 58 |
\def\Head#1{#1\First\Error} |
| 59 |
\def\Tail#1{#1\Second\Error} |
| 60 |
|
| 61 |
\def\Foldl#1#2#3% |
| 62 |
{#3{\Foldl@{#1}{#2}}{#2}} |
| 63 |
\def\Foldl@#1#2#3#4% |
| 64 |
{\Foldl{#1}{#1{#2}{#3}}{#4}} |
| 65 |
\def\Foldr#1#2#3% |
| 66 |
{#3{\Foldr@{#1}{#2}}{#2}} |
| 67 |
\def\Foldr@#1#2#3#4% |
| 68 |
{#1{#3}{\Foldr{#1}{#2}{#4}}} |
| 69 |
|
| 70 |
\def\Cat#1#2{\Foldr\Cons{#2}{#1}} |
| 71 |
|
| 72 |
\def\Reverse{\Foldl{\Twiddle\Cons}\Nil} |
| 73 |
|
| 74 |
\def\All#1{\Foldr{\Compose\And{#1}}\True} |
| 75 |
\def\Some#1{\Foldr{\Compose\Or{#1}}\False} |
| 76 |
\def\Isempty{\All{\First\False}} |
| 77 |
|
| 78 |
\def\Filter#1% |
| 79 |
{\Foldr{\Lift{#1}\Cons\Second}\Nil} |
| 80 |
|
| 81 |
\def\Map#1{\Foldr{\Compose\Cons{#1}}\Nil} |
| 82 |
|
| 83 |
\def\Insert#1#2#3% |
| 84 |
{#3{\Insert@{#1}{#2}}{\Singleton{#2}}} |
| 85 |
\def\Insert@#1#2#3#4% |
| 86 |
{#1{#2}{#3}% |
| 87 |
{\Cons{#2}{\Cons{#3}{#4}}}% |
| 88 |
{\Cons{#3}{\Insert{#1}{#2}{#4}}}} |
| 89 |
\def\Insertsort#1{\Foldr{\Insert{#1}}\Nil} |
| 90 |
|
| 91 |
\def\Unlistize#1{[#1\Unlistize@{}]} |
| 92 |
\def\Unlistize@#1{#1\Foldr\Commaize{}} |
| 93 |
\def\Commaize#1#2{, #1#2} |
| 94 |
|
| 95 |
\def\Listize[#1]% |
| 96 |
{\Listize@#1,\relax]} |
| 97 |
\def\Listize@#1,#2]% |
| 98 |
{\TeXif{\ifx\relax#2}% |
| 99 |
{\Singleton{#1}}% |
| 100 |
{\Cons{#1}{\Listize@#2]}}} |
| 101 |
|
| 102 |
\def\Show#1[#2]% |
| 103 |
{\Unlistize{#1{\Listize[#2]}}} |
| 104 |
|
| 105 |
|