This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent be5d5350f4
commit 25b94b8d85
15 changed files with 380 additions and 45 deletions

View File

@@ -3,30 +3,40 @@
(:require [emptyhead.thought.crud :as thought]
[emptyhead.thought.eval :as eval]
[emptyhead.idea.crud :as idea]
[emptyhead.util.magic :as magic]))
[emptyhead.util.magic :as magic]
[emptyhead.idea.memtag :as memtag]
[emptyhead.idea.protocol :as prtc]))
(defn register-implementation!
[operator impl]
(idea/have-idea! :prefix (str "impl_thought#" (magic/symbolize-ns operator))
:properties [(magic/thought-impl-prop operator)]
:data {:implementation impl}))
(let [impl-prop (magic/thought-impl-prop operator)]
(idea/have-idea! :prefix (str "impl_thought#" (magic/symbolize-ns operator))
:properties [impl-prop]
:shadowing [impl-prop]
:data {:implementation impl})))
(defn register-constructor!
[operator & {:keys [constr-fn defaults]
:or {constr-fn identity
:or {constr-fn (fn [thought parent] {})
defaults {}}}]
(let [constr-op (conj operator :construct)]
(register-implementation!
constr-op
(fn [thought & [parent]]
[parent
(thought/register-thought!
operator
(merge defaults {:operator operator}
(constr-fn (merge parent thought))))]))))
(let [thought (prtc/value thought)
parent (prtc/value parent)]
[parent
(memtag/uid-of
(thought/register-thought!
operator
(merge defaults
(thought/make-thought operator)
{:data (thought/data thought)}
(constr-fn thought parent)
)))])))))
(defn define!
[operator impl & {:keys [constr-fn defaults]
:as constr-args}]
(register-implementation! operator impl)
(register-constructor! operator constr-args))
(register-constructor! operator constr-args) )