diff options
Diffstat (limited to 'src/lux/util.clj')
-rw-r--r-- | src/lux/util.clj | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lux/util.clj b/src/lux/util.clj index 00c0fa6f0..3139cd20b 100644 --- a/src/lux/util.clj +++ b/src/lux/util.clj @@ -211,6 +211,24 @@ ::writer nil ::loader (class-loader!)}) +(defn ^:private with-scope [name body] + (fn [state] + (let [output (body (update-in state [::local-envs] conj (scope name)))] + (match output + [::ok [state* datum]] + [::ok [(update-in state* [::local-envs] rest) datum]] + + _ + output)))) + +(defn with-closure [body] + (fn [state] + (let [body* (with-scope (-> state ::local-envs first :inner-closures str) + body)] + (body* (update-in state [::local-envs] + #(cons (update-in (first %) [:inner-closures] inc) + (rest %))))))) + (do-template [<name> <tag>] (def <name> (fn [state] @@ -222,6 +240,10 @@ get-writer ::writer ) +(def get-scope-name + (fn [state] + [::ok [state (->> state ::local-envs (map :name) reverse (cons (::current-module state)))]])) + (defn with-writer [writer body] (fn [state] (let [output (body (assoc state ::writer writer))] |