A categorical programming language
修订版 | 57c6a0966f649cd6dc613776a0c6feaeb2042c16 (tree) |
---|---|
时间 | 2021-11-27 05:18:14 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Start building basic literate tools.
@@ -0,0 +1,32 @@ | ||
1 | +#!@python3@/bin/python3 | |
2 | + | |
3 | +import sys | |
4 | + | |
5 | +def offset_list(s): | |
6 | + count = 0 | |
7 | + for i, c in enumerate(s): | |
8 | + if c == '(': | |
9 | + count += 1 | |
10 | + elif c == ')': | |
11 | + count -= 1 | |
12 | + if not count: | |
13 | + return i + 1 | |
14 | + raise Exception("Runaway Cammy expression has %d unclosed parentheses" % count) | |
15 | + | |
16 | +def offset_atom(s): | |
17 | + for i, c in enumerate(s): | |
18 | + if c == ' ' or c == '\n': | |
19 | + return i | |
20 | + return len(s) | |
21 | + | |
22 | +def untangle(s): | |
23 | + offset = offset_list(s) if s.startswith('(') else offset_atom(s) | |
24 | + return s[:offset], s[offset:].strip() | |
25 | + | |
26 | +if __name__ == "__main__": | |
27 | + expr, doc = untangle(sys.stdin.read()) | |
28 | + command = sys.argv[1] | |
29 | + if command == "strip": | |
30 | + print(expr) | |
31 | + else: | |
32 | + raise Exception("Unknown command %s" % command) |
@@ -21,7 +21,7 @@ in pkgs.stdenv.mkDerivation { | ||
21 | 21 | |
22 | 22 | buildInputs = [ pkgs.makeWrapper ]; |
23 | 23 | |
24 | - inherit (pkgs) bash chicken; | |
24 | + inherit (pkgs) bash chicken python3; | |
25 | 25 | inherit CHICKEN_REPOSITORY_PATH CHICKEN_INCLUDE_PATH frame jelly movelist; |
26 | 26 | |
27 | 27 | installPhase = '' |
@@ -39,6 +39,10 @@ in pkgs.stdenv.mkDerivation { | ||
39 | 39 | --subst-var frame --subst-var jelly --subst-var movelist |
40 | 40 | chmod +x $out/bin/cammy-simplify |
41 | 41 | |
42 | + substitute $src/cammy-weave.py $out/bin/cammy-weave \ | |
43 | + --subst-var python3 | |
44 | + chmod +x $out/bin/cammy-weave | |
45 | + | |
42 | 46 | makeWrapper ${movelist}/bin/movelist $out/bin/cammy-movelist |
43 | 47 | |
44 | 48 | makeWrapper ${cammy-run}/bin/cammy-run $out/bin/cammy-draw |
@@ -1,3 +1,3 @@ | ||
1 | -(lang dune 2.9) | |
1 | +(lang dune 2.8) | |
2 | 2 | (name frame) |
3 | 3 | (package (name frame) (synopsis "Recursively expand Cammy programs")) |
@@ -1 +1,4 @@ | ||
1 | -(uncurry (pr (curry snd) (curry (comp fun/app succ)))) | |
1 | +(uncurry | |
2 | + (pr | |
3 | + (fun/name id) | |
4 | + (curry (comp fun/app succ)))) |
@@ -15,3 +15,4 @@ | ||
15 | 15 | * Remove movelist djinn, maybe? |
16 | 16 | * Double-negation monad for CPS? |
17 | 17 | * fun/name should always start from 1 |
18 | +* Prove that nat/add is smallest with its behavior |