Skip to content

Commit

Permalink
Added compilable form protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Feb 18, 2024
1 parent 8f9672b commit 03bd4b2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/dev/onionpancakes/chassis/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
(:refer-clojure :exclude [compile])
(:require [dev.onionpancakes.chassis.core :as c]))

(defprotocol CompilableForm
(evaluated? [this]))

(defprotocol CompilableNode
(compilable-node [this]))

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 03bd4b2

Please sign in to comment.