• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A categorical programming language


Commit MetaInfo

修订版fa785ac4caa51c1cba07ad64cd38331ede22201a (tree)
时间2022-07-13 00:40:27
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Display trails in the REPL when available.

更改概述

差异

--- a/cammy-rpy/repl.py
+++ b/cammy-rpy/repl.py
@@ -139,6 +139,7 @@ def repl(hive, stdin, stdout):
139139 print "Not a full command"
140140 command(hive, line[1], line[3:], context)
141141 continue
142+ lineIsAtom = not line.startswith("(")
142143 sexp, trail = parse(line)
143144 # Save the original expr for next time.
144145 mostRecentExpr = sexp
@@ -163,6 +164,14 @@ def repl(hive, stdin, stdout):
163164 print "Couldn't build arrow:", bp.message
164165 except UnificationFailed as uf:
165166 print "Couldn't check type:", uf.message
167+ # Try to print trails for atoms in the hive.
168+ if lineIsAtom:
169+ # Clean the line to improve the odds of success.
170+ line = line.split(" ", 1)[0].strip()
171+ try:
172+ print "Trail:", hive.exprs[line][2].strip()
173+ except KeyError:
174+ pass
166175 return 0
167176
168177 def doREPL(hivepath):
--- /dev/null
+++ b/hive/3b1b-horner.cammy
@@ -0,0 +1 @@
1+(comp (pair (fun/const 3b1b-newton-poly) id) v2/complex/horner)
\ No newline at end of file
--- /dev/null
+++ b/hive/3b1b-newton-poly.cammy
@@ -0,0 +1 @@
1+(l v2/complex/one (l v2/complex/zero (l v2/complex/zero (l v2/complex/one (l (pair f/-1 f-zero) (l v2/complex/one nil))))))
\ No newline at end of file
--- /dev/null
+++ b/hive/f/-1.cammy
@@ -0,0 +1 @@
1+(comp f-one f-negate)
\ No newline at end of file
--- /dev/null
+++ b/hive/l.cammy
@@ -0,0 +1 @@
1+(pair/of cons @0 @1)
\ No newline at end of file
--- /dev/null
+++ b/hive/nat/horner.cammy
@@ -0,0 +1,3 @@
1+(poly/horner zero nat/add nat/mul)
2+
3+Evaluate a polynomial in the natural numbers with Horner's rule.
--- a/hive/poly/horner.cammy
+++ b/hive/poly/horner.cammy
@@ -1,11 +1,15 @@
11 (comp
22 (pair/mapfst list/reverse)
33 (uncurry (fold
4- (fun/name (fun/const zero))
4+ (fun/name (fun/const @0))
55 (curry (comp
66 (pair (pair fstfst (fun/apppair fstsnd snd)) snd)
7- (pair/of nat/add
8- (pair/of nat/mul fstsnd snd)
7+ (pair/of @1
8+ (pair/of @2 fstsnd snd)
99 fstfst))))))
1010
11-Evaluate a polynomial at an input coordinate using Horner's rule.
11+Evaluate a polynomial at an input coordinate using Horner's rule, given:
12+
13+* A target coordinate for the zero polynomial
14+* An addition for coefficients
15+* A multiplication for coordinates
--- /dev/null
+++ b/hive/v2/complex/conjugate.cammy
@@ -0,0 +1 @@
1+(pair/mapsnd f-negate)
\ No newline at end of file
--- /dev/null
+++ b/hive/v2/complex/horner.cammy
@@ -0,0 +1 @@
1+(poly/horner v2/complex/zero v2/complex/add v2/complex/mul)
\ No newline at end of file
--- a/todo.txt
+++ b/todo.txt
@@ -91,8 +91,7 @@
9191 * Would be nice to know how long it takes, too
9292 * Parameterize by number of iterations?
9393 * Native code generation with QBE
94- * Strategy: Emit one procedure for each expression under a (curry) or
95- (uncurry), defunctionalizing
94+ * Strategy: Defunctionalize each (curry) and emit a native procedure
9695 * Should arity be implied, so that these procedures can take their pairs
9796 as two arguments?
9897 * Execution proceeds by compiling our CAM code into QBE templates
@@ -169,7 +168,6 @@
169168 * while-loops and mutable variables
170169 * More jets from natural bytecodes
171170 * snoc = (comp swap cons)
172- * dup
173171 * foldr = (comp list/reverse list/foldl)
174172 * but also, foldl = (comp list/reverse list/foldr)
175173 * so we effectively have fast foldl and fast reverse?
@@ -177,12 +175,11 @@
177175 * reverse is implemented as a tight loop in linear time, but it still
178176 does a linear number of heap allocations
179177 * fun/app = (uncurry id)
178+ * done
180179 * uncurry distills down to fun/app, as in the literature
181180 * (uncurry @0) could be defined as (comp (pair/mapfst @0) fun/app)
182- * Done for nat/add and nat/pred-maybe
183- * Makes Project Euler (6) possible, accelerates demos
184- * pair/swap = (pair snd fst)
185- * this might be fundamental to symmetric monoidal categories or CCCs
181+ * list/uncons
182+ * has particularly simple bytecode, becoming a term op
186183 * Peephole optimization misses opportunities
187184 * Assume two rules
188185 * QUOTE; DUP -> QUOTE (term op)
@@ -201,3 +198,9 @@
201198 * (comp f-log1p f-exp) => (comp (pair (fun/const f-one) id) f/add)
202199 * Lentz's algorithm
203200 * https://en.wikipedia.org/wiki/Lentz's_algorithm
201+* What's a parser again?
202+ * A parser from strings of X to Y: [X] -> Y × [X]
203+ * An instance of state monad
204+ * Multiple results: [X] -> [Y × [X]]
205+ * blends non-determinism and state
206+* Render 3b1b's simple iterated Newton fractal