Add provide/context/emit!/emitted — render-time dynamic scope
Four new primitives for scoped downward value passing and upward accumulation through the render tree. Specced in .sx, bootstrapped to Python and JS across all adapters (eval, html, sx, dom, async). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -162,6 +162,7 @@
|
||||
(= name "reset") (sf-reset args env)
|
||||
(= name "shift") (sf-shift args env)
|
||||
(= name "dynamic-wind") (sf-dynamic-wind args env)
|
||||
(= name "provide") (sf-provide args env)
|
||||
|
||||
;; Higher-order forms
|
||||
(= name "map") (ho-map args env)
|
||||
@@ -949,6 +950,25 @@
|
||||
result))))
|
||||
|
||||
|
||||
;; --------------------------------------------------------------------------
|
||||
;; 6a2. provide — render-time dynamic scope
|
||||
;; --------------------------------------------------------------------------
|
||||
;;
|
||||
;; (provide name value body...) — push a named scope with value and empty
|
||||
;; accumulator, evaluate body, pop scope. Returns last body result.
|
||||
|
||||
(define sf-provide
|
||||
(fn ((args :as list) (env :as dict))
|
||||
(let ((name (trampoline (eval-expr (first args) env)))
|
||||
(val (trampoline (eval-expr (nth args 1) env)))
|
||||
(body-exprs (slice args 2))
|
||||
(result nil))
|
||||
(provide-push! name val)
|
||||
(for-each (fn (e) (set! result (trampoline (eval-expr e env)))) body-exprs)
|
||||
(provide-pop! name)
|
||||
result)))
|
||||
|
||||
|
||||
;; --------------------------------------------------------------------------
|
||||
;; 6b. Macro expansion
|
||||
;; --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user