-
Notifications
You must be signed in to change notification settings - Fork 0
/
syn.meow
112 lines (85 loc) · 1.01 KB
/
syn.meow
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
103
104
105
106
107
108
109
110
111
112
T() {"T"}
F() {"F"}
0() {"0"}
1() {"S0"}
2() {"SS0"}
3() {"SSS0"}
4() {"SSSS0"}
5() {"SSSSS0"}
6() {"SSSSSS0"}
7() {"SSSSSSS0"}
8() {"SSSSSSSS0"}
9() {"SSSSSSSSS0"}
10() {"SSSSSSSSSS0"}
succ(x) {"S"+x}
pred(x) {
1() = 0();
x
}
add (x,y) {
0() = y;
x
}
sub (x,y) {
y = 0();
x
}
mul(x,y) {
"S" = {0()=""; y};
x
}
encode(s) {
var rep = {
"$" = "\$";
"#" = "\#";
"\" = "\\";
s
};
"#$"+ rep +"$#"
}
decode(s) {
var rep = {
"$#" = "";
"#$" = "";
s
};
"\\" = "\";
"\#" = "#";
"\$" = "$";
rep
}
in(x,y) {
not(eq(y,{x=""; y}))
}
not(x) {
if(x, F(), T())
}
or(x,y) {
if(x,T(), y)
}
and(x,y) {
if(x,y,F())
}
eq0(x) {
eq(x, 0())
}
exp(x,y) {
if(
eq0(y),
1(),
mul(
x,
exp(x, pred(y))
)
)
}
leq(x,y) {
in(x,y)
}
wd(x) {
if(
or(eq(x, ""), eq(hd(x)," ")),
"",
hd(x) + wd(tl(x))
)
}