• 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

修订版2f1b1f87b3d72dab11b9eca5556b0c4e781ffdcd (tree)
时间2022-05-08 12:14:18
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Adopt a style for predicates.

更改概述

差异

--- a/default.nix
+++ b/default.nix
@@ -63,7 +63,10 @@ in pkgs.stdenv.mkDerivation {
6363
6464 hive="$lib/lib/cammy/hive/"
6565 echo "Generating documentation for $hive..."
66- $bin/bin/cammy-weave $hive | ${pkgs.pandoc}/bin/pandoc -o $doc/share/doc/hive.pdf --mathml --toc --toc-depth=1
67- $bin/bin/cammy-weave $hive | ${pkgs.pandoc}/bin/pandoc -o $doc/share/doc/hive.html --mathml --toc --toc-depth=1
66+ for ext in pdf html; do
67+ path="$doc/share/doc/hive.$ext"
68+ echo "Generating $path..."
69+ $bin/bin/cammy-weave $hive | ${pkgs.pandoc}/bin/pandoc -o $path --mathml --toc --toc-depth=1
70+ done
6871 '';
6972 }
--- a/hive/about.md
+++ b/hive/about.md
@@ -1,3 +1,8 @@
11 This hive provides some basic tools for approximating and visualizing
22 functions on real numbers. It includes a demonstration renderer for iterated
33 fractal systems.
4+
5+## Style
6+
7+Functions with codomain 2 are called **predicates**. Predicates should end
8+with a question mark, in the Scheme style.
--- a/hive/demo/burning-ship-color.cammy
+++ b/hive/demo/burning-ship-color.cammy
@@ -1,10 +1,4 @@
1-(comp
2- (comp
3- (fractal-membership-color v2/burning-ship (comp nat/32 succ))
4- (monads/maybe/guard (pair/of nat/lte id (fun/const nat/32))))
5- (case
6- (comp (comp nat/to-f f/radians-to-turns) h2rgb)
7- (v3/broadcast f-zero)))
1+(comp (comp (fractal-membership-color v2/burning-ship (comp nat/32 succ)) (monads/maybe/guard (pair/of nat/lt-eq? id (fun/const nat/32)))) (case (comp (comp nat/to-f f/radians-to-turns) h2rgb) (v3/broadcast f-zero)))
82
93 Draw membership for the [Burning Ship
104 fractal](https://en.wikipedia.org/wiki/Burning_Ship_fractal), a relative of
--- /dev/null
+++ b/hive/fifo/empty?.cammy
@@ -0,0 +1,3 @@
1+(pair/of conj (comp fst list/nil?) (comp snd list/nil?))
2+
3+Whether a queue is empty.
--- a/hive/fifo/is_empty.cammy
+++ /dev/null
@@ -1,3 +0,0 @@
1-(pair/of conj (comp fst list/is_empty) (comp snd list/is_empty))
2-
3-Whether a queue is empty.
--- a/hive/fifo/refill.cammy
+++ b/hive/fifo/refill.cammy
@@ -1,7 +1,3 @@
1-(comp
2- (pair (comp snd list/is_empty) id)
3- (uncurry (bool/if
4- (pair (fun/const nil) (comp fst list/reverse))
5- id)))
1+(comp (pair (comp snd list/nil?) id) (uncurry (bool/if (pair (fun/const nil) (comp fst list/reverse)) id)))
62
73 Prepare a queue for a pop by refilling the pop stack.
--- a/hive/fractal-maybe.cammy
+++ b/hive/fractal-maybe.cammy
@@ -1,7 +1,3 @@
1-(comp
2- (comp
3- @0
4- (pair v2/complex/mag-2 (pair left (comp ignore right))))
5- bool/pick)
1+(comp (comp @0 (pair v2/complex/mag-2? (pair left (comp ignore right)))) bool/pick)
62
73 Take a step in an IFS, failing if the step has magnitude 2 or greater.
--- a/hive/fractal-membership-color.cammy
+++ b/hive/fractal-membership-color.cammy
@@ -1,6 +1,4 @@
1-(comp
2- (iter-fractal @0 @1)
3- (comp (list/filter v2/complex/mag-2) list/len))
1+(comp (iter-fractal @0 @1) (comp (list/filter v2/complex/mag-2?) list/len))
42
53 Like fractal-membership, but just returning the length so that we can
64 false-color it.
--- a/hive/fractal-membership.cammy
+++ b/hive/fractal-membership.cammy
@@ -1,6 +1,4 @@
1-(comp
2- (iter-fractal @0 @1)
3- (comp (list/filter v2/complex/mag-2) (comp list/len (f/divpair nat/to-f (fun/const (comp @1 nat/to-f))))))
1+(comp (iter-fractal @0 @1) (comp (list/filter v2/complex/mag-2?) (comp list/len (f/divpair nat/to-f (fun/const (comp @1 nat/to-f))))))
42
53 Measure the degree to which a fractal diverges. Given a maximum number of
64 steps, we iterate the IFS for a fractal in the complex plane until its
--- a/hive/int-fractal-maybe.cammy
+++ b/hive/int-fractal-maybe.cammy
@@ -1,5 +1,3 @@
1-(comp
2- (pair v2/complex/mag-2 (pair left (comp ignore right)))
3- bool/pick)
1+(comp (pair v2/complex/mag-2? (pair left (comp ignore right))) bool/pick)
42
53 Like fractal-maybe, but internal.
--- a/hive/int/is_zero.cammy
+++ /dev/null
@@ -1,3 +0,0 @@
1-(case nat/is_zero nat/is_zero)
2-
3-Whether an integer is zero.
--- /dev/null
+++ b/hive/int/zero?.cammy
@@ -0,0 +1,3 @@
1+(case nat/zero? nat/zero?)
2+
3+Whether an integer is zero.
--- a/hive/list/evens.cammy
+++ b/hive/list/evens.cammy
@@ -1 +1,3 @@
1-(comp list/range (list/filter nat/is_even))
1+(comp list/range (list/filter nat/even?))
2+
3+
--- a/hive/list/filter.cammy
+++ b/hive/list/filter.cammy
@@ -1 +1,4 @@
11 (fold nil (comp (pair (comp fst @0) (pair cons snd)) bool/pick))
2+
3+Apply a predicate to every element of a list, and retain the elements which
4+the predicate admits.
--- a/hive/nat/eq.cammy
+++ /dev/null
@@ -1,5 +0,0 @@
1-(uncurry (pr
2- (curry (comp snd nat/is_zero))
3- (curry (comp (pair fst (comp snd nat/pred)) fun/app))))
4-
5-Equality on natural numbers is decidable.
--- /dev/null
+++ b/hive/nat/eq?.cammy
@@ -0,0 +1,3 @@
1+(uncurry (pr (curry (comp snd nat/zero?)) (curry (comp (pair fst (comp snd nat/pred)) fun/app))))
2+
3+Equality on natural numbers is decidable.
--- a/hive/nat/is_odd.cammy
+++ b/hive/nat/odd?.cammy
@@ -1,3 +1,3 @@
1-(comp nat/is_even not)
1+(comp nat/even? not)
22
33 Whether a natural number is odd.
--- a/hive/pq/insert.cammy
+++ /dev/null
@@ -1,3 +0,0 @@
1-(comp (pair/mapsnd (pair/mapfst pq/singleton)) pq/union)
2-
3-Insert a value into a priority queue.
--- a/todo.txt
+++ b/todo.txt
@@ -47,8 +47,9 @@
4747 * zero -> 0, f-zero -> f-0, f-one -> f-1 maybe?
4848 * eq -> =, e.g. nat/eq -> nat/=
4949 * nat -> n?
50- * Should predicates have a trailing question mark?
50+ * Predicates should have a trailing question mark
5151 * e.g. nat/is_zero -> nat/zero?
52+ * This means f-lt should be f-lt?
5253 * Transcendental and other constants
5354 * Euler's constant e
5455 * done via exponential function