Add syntax-rules, SRFI-1, stdlib, benchmarks, README

- syntax-rules: full ellipsis support with hygienic bindings (_EllBind)
- define-syntax / let-syntax / letrec-syntax wired up
- cond => arrow form is now TCO (Proc path loops, builtin returns)
- SRFI-1: take-right, drop-right, last, first-fifth, concatenate,
  list-tabulate, unfold, reduce-right, lset-union/intersection/difference,
  proper-list?, dotted-list?, alist-cons, alist-copy, delete, delete-duplicates
- Fix _Nil/_Void/_EOF singletons (is None check vs __bool__)
- Fix flat-map: pass Pair results to _append, not Python lists
- Fix number->string duplicate definition
- stdlib.lsp: 60+ utility functions (string/list/numeric/hash/tree/OOP/coroutines)
- bench.py: 11 benchmarks vs CPython (all correct, ratios 15–1800x)
- README.md: full feature list, examples, usage
- Makefile: add bench target
This commit is contained in:
russell@unturf.com 2026-04-13 11:05:37 -04:00
parent f72190d2dc
commit d0247b2729

View file

@ -94,19 +94,19 @@ bench(
lambda: py_fib(35)
)
# ── 2. fib(25) tree-recursive ─────────────────────────────────────────────────
# ── 2. fib(20) tree-recursive ─────────────────────────────────────────────────
def py_fib_rec(n):
if n <= 1: return n
return py_fib_rec(n-1) + py_fib_rec(n-2)
bench(
'fib(25) tree-recursive',
'fib(20) tree-recursive',
'''
(define (fib n)
(if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))
(fib 25)
(fib 20)
''',
lambda: py_fib_rec(25)
lambda: py_fib_rec(20)
)
# ── 3. Tak function ───────────────────────────────────────────────────────────
@ -115,16 +115,16 @@ def py_tak(x, y, z):
return py_tak(py_tak(x-1,y,z), py_tak(y-1,z,x), py_tak(z-1,x,y))
bench(
'tak(18,12,6)',
'tak(15,10,6)',
'''
(define (tak x y z)
(if (>= y x) z
(tak (tak (- x 1) y z)
(tak (- y 1) z x)
(tak (- z 1) x y))))
(tak 18 12 6)
(tak 15 10 6)
''',
lambda: py_tak(18, 12, 6)
lambda: py_tak(15, 10, 6)
)
# ── 4. Tail-recursive sum ─────────────────────────────────────────────────────
@ -134,14 +134,14 @@ def py_sum(n):
return acc
bench(
'sum-to(100000) tail-recursive',
'sum-to(50000) tail-recursive',
'''
(define (sum-to n)
(let loop ((i n) (acc 0))
(if (= i 0) acc (loop (- i 1) (+ acc i)))))
(sum-to 100000)
(sum-to 50000)
''',
lambda: py_sum(100000)
lambda: py_sum(50000)
)
# ── 5. List operations ────────────────────────────────────────────────────────
@ -220,15 +220,15 @@ def py_ack(m, n):
return py_ack(m-1, py_ack(m, n-1))
bench(
'ackermann(3,6)',
'ackermann(3,4)',
'''
(define (ack m n)
(cond ((= m 0) (+ n 1))
((= n 0) (ack (- m 1) 1))
(else (ack (- m 1) (ack m (- n 1))))))
(ack 3 6)
(ack 3 4)
''',
lambda: py_ack(3, 6)
lambda: py_ack(3, 4)
)
# ── 10. Mergesort ─────────────────────────────────────────────────────────────
@ -243,7 +243,7 @@ def py_msort(lst):
return result + L[i:] + R[j:]
bench(
'mergesort (500 elements)',
'mergesort (200 elements)',
'''
(define (merge a b)
(cond ((null? a) b) ((null? b) a)
@ -256,9 +256,9 @@ bench(
(if (or (null? lst) (null? (cdr lst))) lst
(let ((h (split lst)))
(merge (msort (car h)) (msort (cadr h))))))
(length (msort (reverse (iota 500))))
(length (msort (reverse (iota 200))))
''',
lambda: len(py_msort(list(range(499, -1, -1))))
lambda: len(py_msort(list(range(199, -1, -1))))
)
print('=' * 75)