From 02253c40be72355f34badd50ec70f3df00a96898 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Mon, 22 Apr 2024 13:44:52 -0500 Subject: [PATCH] flatten :let --- src/compojure/api/meta.clj | 39 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/compojure/api/meta.clj b/src/compojure/api/meta.clj index c061d4b3..21df0aaf 100644 --- a/src/compojure/api/meta.clj +++ b/src/compojure/api/meta.clj @@ -810,6 +810,12 @@ (= sym 'if)) (static-body? &env (next form))))))))) +(defn- resolve-var [&env sym] + (when (symbol? sym) + (let [v (resolve &env sym)] + (when (var? v) + v)))) + (defn- static-resolved-form? [&env form] (boolean (or (and (seq? form) @@ -832,12 +838,6 @@ (when-not (identical? form' form) (static-form? &env form')))))) -(defn- resolve-var [&env sym] - (when (symbol? sym) - (let [v (resolve &env sym)] - (when (var? v) - v)))) - (defn- constant-form? [&env form] (or ((some-fn nil? keyword? number? boolean? string?) form) (and (seq? form) @@ -872,15 +872,24 @@ (defn- static-binder-env [&env bv] (when (and (vector? bv) (even? (count bv))) - (reduce (fn [&env [l init]] - (if-not (or (simple-symbol? l) - (simple-keyword? l) ;;for - (static-form? init)) - (reduced nil) - (cond-> &env - (simple-symbol? l) - (assoc l true)))) - (or &env {}) (partition 2 bv)))) + (let [flat (eduction + (partition-all 2) + (mapcat (fn [[l init]] + (if (and (= :let l) + (even? count init)) + (partition-all 2 init) + [[l init]]))) + bv)] + (reduce (fn [&env [l init]] + (if-not (or (simple-symbol? l) + (simple-keyword? l) ;;for + (static-form? init)) + (reduced nil) + (cond-> &env + (simple-symbol? l) + (assoc l true)))) + (or &env {}) + flat)))) (defn- static-let? [&env form] (and (seq? form)