Skip to content

Commit

Permalink
factored vector-children fn out of the Node protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Feb 22, 2024
1 parent d74248b commit b00124d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
31 changes: 19 additions & 12 deletions src/dev/onionpancakes/chassis/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -486,19 +486,26 @@
(send-warn-on-ambig-attrs! *form* elem))
(compilable-element-children-attrs-ambig elem)))))

(defn compilable-vector-children
[this]
(if (c/element-vector? this)
(if (c/alias-element? this)
(compilable-alias-element-children this)
(compilable-element-children this))
this))

(defn vector-children
[this]
(if *evaluated*
(c/vector-children this)
(compilable-vector-children this)))

(extend clojure.lang.IPersistentVector
CompilableNode
{:branch? (fn [_] true)
:children vector-children})

(extend-protocol CompilableNode
clojure.lang.IPersistentVector
(branch? [_] true)
(children [this]
(if (c/element-vector? this)
(if (c/alias-element? this)
(if *evaluated*
(c/alias-element-children this)
(compilable-alias-element-children this))
(if *evaluated*
(c/element-children this)
(compilable-element-children this)))
this))
clojure.lang.ISeq
(branch? [_]
(boolean *evaluated*))
Expand Down
21 changes: 13 additions & 8 deletions src/dev/onionpancakes/chassis/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1346,15 +1346,20 @@
(let [head (.nth elem 0 nil)]
(some? (namespace head))))

(defn vector-children
[this]
(if (element-vector? this)
(if (alias-element? this)
(alias-element-children this)
(element-children this))
this))

(extend clojure.lang.IPersistentVector
Node
{:branch? (fn [_] true)
:children vector-children})

(extend-protocol Node
clojure.lang.IPersistentVector
(branch? [this] true)
(children [this]
(if (element-vector? this)
(if (alias-element? this)
(alias-element-children this)
(element-children this))
this))
clojure.lang.ISeq
(branch? [this] true)
(children [this] this)
Expand Down

0 comments on commit b00124d

Please sign in to comment.