Start implementing EH stdlib

This commit is contained in:
2026-01-23 11:08:52 +01:00
parent 187ba48dcf
commit 6db315a244
9 changed files with 217 additions and 9 deletions

View File

@@ -0,0 +1,29 @@
(ns emptyhead.newlib.math.arithmetic
"Airthmetic operators."
(:require [emptyhead.thought.define :as def]
[emptyhead.thought.crud :as thought]
[emptyhead.newlib.message :as msg]))
;; Initial addition, e.g. =5 +=. Returns partially applied pointer.
(def/define! [:EH :PRIM [:EH :PRIM :NUM] :+]
(fn [thought parent]
(let [to (:to (thought/data parent))
pointer (-> (str "PART<" to "+_>.") gensym keyword)
th (thought/register-thought! [:EH :PRIM :PARTIAL :+] :transient false :data to)]
(msg/register-impl pointer [:EH :PRIM :NUM] th)
[parent pointer])))
;; Final addition, e.g. =(5 +) 5=. Returns a thunk.
(def/define! [:EH :PRIM :PARTIAL :+]
(fn [thought parent]
(let [from (:from (thought/data parent))
to (thought/data thought)
pointer (-> (str "LAZY<" from "+" to">.") gensym keyword)
lazy (thought/register-thought! [:EH :PRIM :LAZY :+] :transient true :data [from to])]
(msg/register-impl pointer [:EH :PRIM :REIFY] lazy)
[parent pointer])))
(def/define! [:EH :PRIM :LAZY :+]
(fn [thought parent]
(let [[from to] (thought/data thought)]
[parent (+ from to)])))