flow: branch combinator (conditional) + 6 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
Phase 2 control flow. (branch pred then else) selects then/else node by running pred on the threaded input; named 'branch' since 'cond' is a Scheme special form. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
;; Scheme interpreter so that Phase 3's `suspend` (call/cc) can capture the
|
||||
;; flow continuation directly.
|
||||
;;
|
||||
;; Phase 1 combinators:
|
||||
;; Phase 1 combinators (flow-combinators-src):
|
||||
;; (flow-node f) — wrap a 1-arg procedure as a node (identity)
|
||||
;; (flow-id input) — pass the upstream value through unchanged
|
||||
;; (flow-const v) — node that ignores input and yields v
|
||||
@@ -15,15 +15,24 @@
|
||||
;; (parallel n ...) — fan input to every child, join results into a list
|
||||
;; (SEQUENTIAL evaluation; true concurrency is Phase 3)
|
||||
;; (defflow name body)— bind a named flow
|
||||
;;
|
||||
;; Phase 2 combinators (flow-control-src):
|
||||
;; (branch pred then else) — pred on input selects then/else node
|
||||
;; (`cond` is a Scheme special form, so the combinator is named `branch`)
|
||||
|
||||
(define
|
||||
flow-combinators-src
|
||||
"(define (flow-node f) f)\n (define (flow-id input) input)\n (define (flow-const v) (lambda (input) v))\n (define (flow-seq-step ns v)\n (if (null? ns) v (flow-seq-step (cdr ns) ((car ns) v))))\n (define sequence (lambda ns (lambda (input) (flow-seq-step ns input))))\n (define parallel (lambda ns (lambda (input) (map (lambda (n) (n input)) ns))))\n (define-syntax defflow\n (syntax-rules ()\n ((defflow nm body) (define nm body))))")
|
||||
|
||||
(define
|
||||
flow-control-src
|
||||
"(define (branch pred then else)\n (lambda (input) (if (pred input) (then input) (else input))))")
|
||||
|
||||
(define
|
||||
flow-load-combinators!
|
||||
(fn
|
||||
(env)
|
||||
(begin
|
||||
(scheme-eval-program (scheme-parse-all flow-combinators-src) env)
|
||||
(scheme-eval-program (scheme-parse-all flow-control-src) env)
|
||||
env)))
|
||||
|
||||
Reference in New Issue
Block a user