From b00124d47fe0ee76fce81172e3061b94a1b911c4 Mon Sep 17 00:00:00 2001 From: onionpancakes <639985+onionpancakes@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:55:40 -0800 Subject: [PATCH] factored vector-children fn out of the Node protocol --- src/dev/onionpancakes/chassis/compiler.clj | 31 +++++++++++++--------- src/dev/onionpancakes/chassis/core.clj | 21 +++++++++------ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/dev/onionpancakes/chassis/compiler.clj b/src/dev/onionpancakes/chassis/compiler.clj index 67efb23..68c0a3a 100644 --- a/src/dev/onionpancakes/chassis/compiler.clj +++ b/src/dev/onionpancakes/chassis/compiler.clj @@ -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*)) diff --git a/src/dev/onionpancakes/chassis/core.clj b/src/dev/onionpancakes/chassis/core.clj index c9a0456..6d178bb 100644 --- a/src/dev/onionpancakes/chassis/core.clj +++ b/src/dev/onionpancakes/chassis/core.clj @@ -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)