Skip to content

Commit

Permalink
feat: lazycat
Browse files Browse the repository at this point in the history
  • Loading branch information
linsyking committed Apr 5, 2023
1 parent 033f35b commit b986dac
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 201 deletions.
132 changes: 0 additions & 132 deletions examples/iexpr.meow

This file was deleted.

43 changes: 32 additions & 11 deletions examples/syn.cat
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
true = "T"
false = "F"
zero = "0"
true = "T"
false = "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 = cat "S" x
pred x = let "S0" "0" x
add x y = let "0" y x
sub x y = let y "0" x
mul x y = let "S" let "0" "" y x
pred x = let 1 0 x
add x y = let 0 y x
sub x y = let y 0 x
mul x y = let "S" let 0 "" y x
dr x y z = let y x let x y z
encode s = cat cat "#$" let "$" "\$" let "#" "\#" let "\" "\\" s "$#"
decode s = let "\\" "\" let "\$" "$" let "\#" "#" let "_#" "" let "_$" "" s
decode s = let "\\" "\" let "\#" "#" let "\$" "$" let "$#" "" let "#$" "" s
encat x y = cat let "#$" "" x let "$#" "" y
enraw s = let "#$" "" let "$#" "" encode s
enrep s x y = let enraw x y s
rep2 s x xr y yr = decode let "x$" enraw xr let "y$" enraw yr enrep enrep encode s x "x$" y "y$"
rep2 s x xr y yr = decode let "x#" enraw xr let "y#" enraw yr enrep enrep encode s x "x#" y "y#"
eq x y = let encode x "F" let encode y "T" encode x
if c x y = decode let "T$" encode x let "F$" encode y cat c "$"
if c x y = decode let "T#" encode x let "F#" encode y cat c "#"
in x y = not eq y let x "" y
not x = if x false true
ife x = eq x ""
eq0 x = eq x 0
factorial x = if eq x 1 1 mul x factorial pred x
digit x = let "1" 1 let "2" 2 let "3" 3 let "4" 4 let "5" 5 let "6" 6 let "7" 7 let "8" 8 let "9" 9 x
exp x y = if eq0 y 1 mul x exp x pred y
nrep x p = let "0" p let "1" p let "2" p let "3" p let "4" p let "5" p let "6" p let "7" p let "8" p let "9" p x
len x = cat nrep x "S" 0
revdigit x = let 1 "1" let 2 "2" let 3 "3" let 4 "4" let 5 "5" let 6 "6" let 7 "7" let 8 "8" let 9 "9" x
head x = pred cat nrep let "$0" let "0" "" cat "S" 0 let "$1" let "0" "" cat "S" 1 let "$2" let "0" "" cat "S" 2 let "$3" let "0" "" cat "S" 3 let "$4" let "0" "" cat "S" 4 let "$5" let "0" "" cat "S" 5 let "$6" let "0" "" cat "S" 6 let "$7" let "0" "" cat "S" 7 let "$8" let "0" "" cat "S" 8 let "$9" let "0" "" cat "S" 9 cat "$" x "" 0
num x = if eq len x 1 digit x add mul head x exp succ 9 pred len x num let cat "$" revdigit head x "" cat "$" x
leq x y = in x y
show x = if leq len x 9 revdigit x cat show let "SSSSSSSSSS" "S" sub x let "SSSSSSSSSS" "" x revdigit let "SSSSSSSSSS" "" x
fib x = if eq0 x 0 if leq x 2 1 add fib pred x fib pred pred x
Loading

0 comments on commit b986dac

Please sign in to comment.