• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

A categorical programming language


Commit MetaInfo

修订版81459e9386e44e14957806fbb6e9004066929f2a (tree)
时间2022-08-27 10:54:50
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Start on a new REPL which interacts with honey.

更改概述

差异

--- a/honey.py
+++ b/honey.py
@@ -1,7 +1,7 @@
11 import json
22 import os
33
4-from flask import Flask, jsonify, url_for
4+from flask import Flask, abort, jsonify, url_for
55
66 app = Flask(__name__)
77
@@ -24,5 +24,7 @@ def resolve(i):
2424
2525 @app.route("/dip/<path:name>")
2626 def dip(name):
27+ if name not in symbols:
28+ abort(404)
2729 index, trail = symbols[name]
2830 return jsonify({"expr": resolve(index), "trail": trail})
--- /dev/null
+++ b/new-repl.py
@@ -0,0 +1,49 @@
1+#!/usr/bin/env nix-shell
2+#! nix-shell -i python -p python3Packages.requests python3Packages.click-repl
3+
4+from textwrap import dedent
5+
6+import click
7+import click_repl
8+
9+import requests
10+
11+@click.group()
12+def cli():
13+ pass
14+
15+def getJSON(url):
16+ try:
17+ return requests.get(url).json()
18+ except requests.exceptions.JSONDecodeError:
19+ click.echo("Server response was not JSON")
20+
21+@cli.command()
22+def size():
23+ dippers = getJSON("http://localhost:5000/dippers")
24+ if dippers:
25+ click.echo("got dippers")
26+ click.echo(len(dippers))
27+
28+def sexpify(expr):
29+ if isinstance(expr, list):
30+ return "(" + " ".join(sexpify(x) for x in expr) + ")"
31+ else: return expr
32+
33+@cli.command()
34+@click.argument("name")
35+def show(name):
36+ obj = getJSON("http://localhost:5000/dip/" + name)
37+ if obj:
38+ trail = obj["trail"].strip()
39+ expr = sexpify(obj["expr"])
40+ click.echo(dedent("""
41+ Name: {name}
42+ Trail: {trail}
43+ Dipped form: {expr}
44+ """).strip().format(name=name, trail=trail, expr=expr))
45+
46+click_repl.register_repl(cli)
47+
48+if __name__ == "__main__":
49+ cli()
--- a/todo.txt
+++ b/todo.txt
@@ -150,28 +150,6 @@
150150 * Zipper for lists looks like existing FIFO code, just needs the helpers
151151 * Lenses?
152152 * Project Euler
153- 1) need division for nats or way to generate repeating lists
154- 2) need to run Fibonacci state machine for given number of steps
155- 3) factorization for nats
156- 4) unclear how to proceed
157- 5) turn numbers into multisets of factors (Gödel style), take union of
158- multisets with maximum of each coefficient
159- 7) need the function N -> N which indexes the primes
160- 8) more digit-manipulation BS
161- 9) not really a programming exercise; we could implement the algorithm for
162- generating Pythagorean triples
163- 10) could generate a list of primes and sum it
164- 11) need to eat a file as input
165- 12) not really programming
166- 13) need to eat input file
167- 14) Collatz sequence
168- 15) combinatorial question, doesn't actually require geometry
169- 16) looks like a digit-manipulation question, but probably isn't done with
170- brute-force computation
171- 17) definitely a digit-manipulation question
172- 18) A* through a given graph
173- 19) Conway's Doomsday algorithm
174- 20) oh look, digit manipulation
175153 * take every third element in a list
176154 * Useful for (1) and (2)
177155 * enumerate the primes
@@ -179,6 +157,8 @@
179157 * compute binomial coefficients
180158 * Useful in general, would solve (15)
181159 * (15) is solved by f(n) = binomial(2n, n)
160+ * count digits or do comparisons with big numbers
161+ * (25) just asks for a few thousand elements of Fibonacci
182162 * Can we use bits/exp-sqr to speed up iteration of endomorphisms?
183163 * needs zero, succ, double
184164 * Given f : X -> X, (fun/name f) : 1 -> [X, X] is the succ
@@ -355,6 +335,9 @@
355335 * {"pair/mapfst": ["pair", ["comp", "fst", "@0"], "snd"], ...}
356336 * Could still allow for trails
357337 * Edits and summaries could now be done with jq
338+ * Prototype is done
339+ * Can be served with "honey" Flask app
340+ * Doing edits/summaries/queries with jq is painful, so let's avoid jq
358341 * IDE that recognizes types
359342 * Sees a type like [X] -> ... and calls it "a natural transformation from
360343 lists to ..."