From 03bd4b286f3dbb6350645af66e19000afffb5f60 Mon Sep 17 00:00:00 2001 From: onionpancakes <639985+onionpancakes@users.noreply.github.com> Date: Sat, 17 Feb 2024 17:54:19 -0800 Subject: [PATCH] Added compilable form protocol --- src/dev/onionpancakes/chassis/compiler.clj | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/dev/onionpancakes/chassis/compiler.clj b/src/dev/onionpancakes/chassis/compiler.clj index 7e1126e..8ca6cfb 100644 --- a/src/dev/onionpancakes/chassis/compiler.clj +++ b/src/dev/onionpancakes/chassis/compiler.clj @@ -2,6 +2,9 @@ (:refer-clojure :exclude [compile]) (:require [dev.onionpancakes.chassis.core :as c])) +(defprotocol CompilableForm + (evaluated? [this])) + (defprotocol CompilableNode (compilable-node [this])) @@ -33,7 +36,27 @@ (eduction compact-xf) (vec))) -;; Compilable +;; CompilableForm + +(extend-protocol CompilableForm + clojure.lang.IPersistentCollection + (evaluated? [this] + (every? evaluated? this)) + clojure.lang.Keyword + (evaluated? [_] true) + clojure.lang.ISeq + (evaluated? [_] false) + clojure.lang.Symbol + (evaluated? [_] false) + ;; This catches Strings, constant Numbers, and a bit more. + java.lang.constant.Constable + (evaluated? [_] true) + Object + (evaluated? [_] false) + nil + (evaluated? [_] true)) + +;; CompilableNode (defn attrs-present? [elem]