Skip to content

Commit

Permalink
flatten :let
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Apr 22, 2024
1 parent c49cc44 commit 02253c4
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 02253c4

Please sign in to comment.