Start implementing EH stdlib
This commit is contained in:
29
src/cljs/emptyhead/newlib/math/arithmetic.cljs
Normal file
29
src/cljs/emptyhead/newlib/math/arithmetic.cljs
Normal 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)])))
|
||||
Reference in New Issue
Block a user