• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

A categorical programming language


Commit MetaInfo

修订版90d9bc9042fe04d7cc376d16dfb049446b5031d9 (tree)
时间2022-03-12 23:26:47
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Build a DAG while loading expressions into a hive.

更改概述

差异

--- a/cammy-rpy/cammylib/hive.py
+++ b/cammy-rpy/cammylib/hive.py
@@ -16,6 +16,7 @@ class Hive(object):
1616 def __init__(self, hivepath):
1717 self.hivepath = hivepath
1818 self.exprs = {}
19+ self.dag = {}
1920
2021 def load(self, atom):
2122 if atom in self.exprs:
@@ -27,6 +28,9 @@ class Hive(object):
2728 try:
2829 with open(fullpath, "r") as handle:
2930 sexp, trail = parse(handle.read())
31+ symbols = {}
32+ sexp.symbols(symbols)
33+ self.dag[atom] = symbols
3034 sexp = sexp.canonicalize(self)
3135 self.exprs[atom] = sexp
3236 # print("Loaded", atom, sexp)
--- a/cammy-rpy/cammylib/sexp.py
+++ b/cammy-rpy/cammylib/sexp.py
@@ -27,6 +27,9 @@ class Atom(SExp):
2727 def asStr(self):
2828 return self.symbol
2929
30+ def symbols(self, s):
31+ s[self.symbol] = None
32+
3033 def substitute(self, args):
3134 return self
3235
@@ -65,6 +68,11 @@ class Functor(SExp):
6568 args = " ".join([arg.asStr() for arg in self.arguments])
6669 return "(%s %s)" % (self.constructor, args)
6770
71+ def symbols(self, s):
72+ s[self.constructor] = None
73+ for arg in self.arguments:
74+ arg.symbols(s)
75+
6876 def substitute(self, args):
6977 return Functor(self.constructor,
7078 [arg.substitute(args) for arg in self.arguments])
@@ -120,6 +128,9 @@ class Hole(SExp):
120128 def asStr(self):
121129 return "@%d" % self.index
122130
131+ def symbols(self, s):
132+ pass
133+
123134 def substitute(self, args):
124135 return args[self.index]
125136
--- a/default.nix
+++ b/default.nix
@@ -3,6 +3,7 @@ let
33 inherit (nixpkgs) pkgs;
44 jelly = (import jelly/Cargo.nix { pkgs = nixpkgs; }).rootCrate.build;
55 movelist = import ./movelist { inherit nixpkgs; };
6+ cammy-comb = import ./cammy-rpy/comb.nix { inherit nixpkgs jelly; };
67 cammy-draw = import ./cammy-rpy/draw.nix { inherit nixpkgs jelly; };
78 cammy-frame = import ./cammy-rpy/frame.nix { inherit nixpkgs jelly; };
89 cammy-repl = import ./cammy-rpy/repl.nix { inherit nixpkgs jelly; };
@@ -25,6 +26,7 @@ in pkgs.stdenv.mkDerivation {
2526 makeWrapper ${jelly}/bin/jelly $out/bin/cammy-jelly
2627
2728 # RPython tools
29+ makeWrapper ${cammy-comb}/bin/cammy-comb $out/bin/cammy-comb
2830 makeWrapper ${cammy-draw}/bin/cammy-draw $out/bin/cammy-draw
2931 makeWrapper ${cammy-frame}/bin/cammy-frame $out/bin/cammy-frame
3032 makeWrapper ${cammy-repl}/bin/cammy-repl $out/bin/cammy-repl
--- /dev/null
+++ b/hive/bool/if.cammy
@@ -0,0 +1,3 @@
1+(comp either (case (fun/name @0) (fun/name @1)))
2+
3+As close as we can get to an if-expression.
--- a/hive/fun/iter.cammy
+++ b/hive/fun/iter.cammy
@@ -1 +1,3 @@
11 (pr (fun/name id) (comp (pair id (fun/const (fun/name @0))) fun/int-comp))
2+
3+Iterate a given arrow zero or more times.
--- /dev/null
+++ b/hive/fun/observe.cammy
@@ -0,0 +1,3 @@
1+(fun/flip (comp (pair (fun/const (fun/name @0)) (fun/iter @1)) fun/int-comp))
2+
3+Observe the value of an endomorphism after a specified number of iterations.
--- /dev/null
+++ b/hive/list/append.cammy
@@ -0,0 +1,3 @@
1+(comp (pair/mapfst list/reverse) list/reverse-onto)
2+
3+Concatenate two lists into a single list.
--- /dev/null
+++ b/hive/list/double.cammy
@@ -0,0 +1,3 @@
1+(fold nil (comp (pair fst cons) cons))
2+
3+Repeat each value in a list twice.
--- /dev/null
+++ b/hive/nat/double-alt.cammy
@@ -0,0 +1,3 @@
1+(pr zero (comp succ succ))
2+
3+Double a natural number by counting every successor operation twice.
--- a/hive/nat/double.cammy
+++ b/hive/nat/double.cammy
@@ -1 +1,3 @@
11 (comp fun/dup nat/add)
2+
3+Double a natural number by adding it to itself.
--- /dev/null
+++ b/hive/nat/rshift.cammy
@@ -0,0 +1,8 @@
1+(pr
2+ (pair zero f)
3+ (fun/apppair
4+ (comp snd (bool/if (pair succ (fun/const f)) (pair id (fun/const t))))
5+ fst))
6+
7+Shift all of the bits in a natural number towards the least-significant bit.
8+The least-significant bit itself is also returned.
--- /dev/null
+++ b/hive/pair/mapfst.cammy
@@ -0,0 +1,3 @@
1+(pair (comp fst @0) snd)
2+
3+Map over the first component of a pair.
--- /dev/null
+++ b/hive/pair/mapsnd.cammy
@@ -0,0 +1,3 @@
1+(pair fst (comp snd @0))
2+
3+Map over the second component of a pair.
--- a/shell.nix
+++ b/shell.nix
@@ -14,7 +14,9 @@ in pkgs.stdenv.mkDerivation {
1414 egg2nix
1515 # maintaining cammy-rpy/
1616 pythonPackages.pyflakes
17- # developing cammy-weave
17+ # using cammy-comb
18+ graphviz
19+ # using cammy-weave
1820 pandoc texlive.combined.scheme-small
1921 # using cammy-repl
2022 rlwrap
--- a/todo.txt
+++ b/todo.txt
@@ -6,7 +6,6 @@
66 * list/eq : [X × X, 2] → [[X] × [X], 2]
77 * list/zip : [X] × [Y] → [X × Y]
88 * list/tail : [X] → [X]
9-* list/append : [X] × [X] → [X]
109 * rat
1110 * refactoring from the bikeshed: ignore -> !
1211 * Might not be important since fun/const is the only user!
@@ -43,11 +42,9 @@
4342 * X -> X: should be id?
4443 * X -> 1: should be ignore
4544 * 1 -> 2: should be t or f
46-* New int type
47- * Current type: quotient of N × N under subtraction
48- * big, tricky case analysis, big quotient overlap
49- * Proposed type: quotient of N + N gluing zero
50- * almost minimal, sign bit, quotient glues exactly two elements into one
5145 * Refactoring tools
5246 * Find all leaves in a hive
5347 * Rename an expression and change all callers
48+* Maybe allow inductive datatype definitions during toolchain build time
49+ * Start by factoring out N and lists into inductive datatype modules somehow
50+ * Then add trees, etc.