48 lines
2.1 KiB
Clojure
48 lines
2.1 KiB
Clojure
(ns emptyhead.newlib.math.arithmetic
|
|
"Airthmetic operators."
|
|
(:require [emptyhead.thought.define :as def]
|
|
[emptyhead.thought.crud :as thought]
|
|
[emptyhead.newlib.message :as msg]
|
|
[emptyhead.newlib.delegate :as del]
|
|
[emptyhead.thought.extend :as extend]
|
|
[emptyhead.thought.eval :as eval]
|
|
[emptyhead.newlib.util :as util]))
|
|
;; TODO values are now consumed when used instantly, this will give issues once we have variables
|
|
|
|
;; 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))
|
|
th (thought/register-thought! [:EH :IO :RETURN]
|
|
:data to
|
|
:reference (str "<" to "+_>"))]
|
|
|
|
(del/add-delegate th [:EH :PRIM :PARTIAL :+])
|
|
[parent th])))
|
|
|
|
;; Final addition, e.g. =(5 +) 5=.
|
|
(def/define! [:EH :PRIM :PARTIAL :+ [:EH :PRIM :NUM]]
|
|
(fn [thought parent]
|
|
(let [from (:from (thought/data parent))
|
|
[_ to] (thought/pop-stack (eval/execute! (:to (thought/data parent)) parent))
|
|
th (thought/register-thought! [:EH :IO :RETURN]
|
|
:data [to from]
|
|
:reference (str "<" to "+" from ">"))]
|
|
(del/add-delegate th [:EH :LAZY [:EH :PRIM :NUM]])
|
|
[parent th])))
|
|
|
|
(def/define! [:EH :LAZY [:EH :PRIM :NUM] :REIFY]
|
|
(fn [thought parent]
|
|
(let [[_ [to from]] (thought/pop-stack (eval/execute! (:to (thought/data parent)) parent))
|
|
to (if (symbol? to) (msg/apply-msg to [:EH :REIFY]) to)
|
|
from (if (symbol? from) (msg/apply-msg to [:EH :REIFY]) from)]
|
|
[parent (+ to from)])))
|
|
|
|
(del/add-delegate [:EH :LAZY [:EH :PRIM :NUM]] [:EH :PRIM :NUM])
|
|
|
|
(thought/register-singleton! [:EH :PRIM :PARTIAL :+ [:EH :PRIM :NUM]])
|
|
(msg/register-single-impl [:EH :PRIM :PARTIAL :+] [:EH :PRIM :NUM] [:EH :PRIM :PARTIAL :+ [:EH :PRIM :NUM]])
|
|
|
|
(thought/register-singleton! [:EH :LAZY [:EH :PRIM :NUM] :REIFY])
|
|
(msg/register-single-impl [:EH :LAZY [:EH :PRIM :NUM]] [:EH :REIFY] [:EH :LAZY [:EH :PRIM :NUM] :REIFY])
|