-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayground.tex
102 lines (90 loc) · 2.49 KB
/
playground.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
\errorcontextlines99
\input chr.tex
\makeatletter
\def\fail{\errmessage{FAIL}}
\def\yes{\chr@log{YES}}
\def\tuplehelper#1:#2\@nil{\def\fst{#1}\def\snd{#2}}
\def\tuple#1{\edef\@tmp{#1}\expandafter\tuplehelper\@tmp\@nil}
% plain tex has no default add
\def\add#1#2{\chr@tempcount=#1\relax\advance\chr@tempcount by #2\relax\edef\res{\the\chr@tempcount}}
\chr{List Test}{
\makelist{example}{1,2,3,4}
\listequal{example}{example} \yes \else \fail \fi
\makelist{example2}{1,2,3,4}
\listequal{example}{example2} \yes \else \fail \fi
\makelist{example3}{1,2,3,4,5}
\listequal{example}{example3} \fail \else \yes \fi
\makelist{example4}{1,2,4,3}
\listequal{example}{example4} \fail \else \yes \fi
}
\chr{Permute Test}{
\makelist{example}{1,2,3}
\def\chr@@output{\chr@list@log{example}}
\permute{example}{2}
}
% % i like patterns more than pattern tbh.
% for a pattern, '\c' is always the constraint passed!
\chr{Match Test}{%
\makelist{constraints}{1,2,3,4}%
\makelist{patterns}{%
{\ifnum\c>2},
{\ifnum\c>0}%
}
\match{patterns}{constraints}
}
\chr{Rule Test}{%
\makelist{constraints}{1,2,3,4}%
\Rule{base-case}{}{{\ifnum\c1>0}}{\true}{}%
\chr@program@get{chr@toreturn}{constraints}
\Rule{fun}{{\ifnum\c1>2}}{{\ifnum\c1>0}}{\true}{3}%
\chr@program@get{chr@toreturn}{constraints}
\chr@list@log{chr@constraints}%
}
\chr{Compose Test}{%
\makelist{chr@constraints}{1,2,3,4}%
\Compose{%
\Rule{base-case}{}{{\ifnum\c1>0}}{\true}{2}%
\Rule{fun}{{\ifnum\c1>2}}{{\ifnum\c1>0}}{\true}{3}%
}%
\chr@program@get{composite_solver}{chr@constraints}
\chr@list@log{chr@constraints}%
}
\chr{fib test}{%
\makelist{chr@constraints}{{0:1}}%
\Compose{
\Rule{main}%
{} % empty kept head
{{\true}} % removed head
{\true}
{%
\tuple{\c{0}}%
\add{\fst}{\snd}%
% ebody expands its argument to replace
\ebody{\snd:\res}%
}
}
\chr@program@get{composite_solver}{chr@constraints}
% manually apply additional times
\chr@program@get{composite_solver}{chr@constraints}
\chr@list@log{chr@constraints}%
}
\chr{fib test}{%
\enablelog
\LimitCycles{25}
\Compose{
\Rule{main}%
{} % empty kept head
{{\true}} % removed head
{\true}
{%
\tuple{\c{0}}%
\add{\fst}{\snd}%
% ebody expands its argument to replace
\ebody{\snd:\res}%
}
}
\Run{{0:1}}
% print it to file :3
\printlist{chr@constraints}%
}
\bye