Native ref fns
This commit is contained in:
parent
b1022ad832
commit
8cbc516a66
|
@ -1,6 +1,7 @@
|
||||||
(ns ludus.prelude
|
(ns ludus.prelude
|
||||||
(:require
|
(:require
|
||||||
[ludus.data :as data]
|
[ludus.data :as data]
|
||||||
|
[ludus.interpreter :as interp]
|
||||||
[ludus.show]))
|
[ludus.show]))
|
||||||
|
|
||||||
(def eq {:name "eq"
|
(def eq {:name "eq"
|
||||||
|
@ -45,6 +46,22 @@
|
||||||
(println (apply str args))
|
(println (apply str args))
|
||||||
:ok)})
|
:ok)})
|
||||||
|
|
||||||
|
(def deref- {:name "deref"
|
||||||
|
::data/type ::data/clj
|
||||||
|
:body (fn [ref]
|
||||||
|
(if (::data/ref ref)
|
||||||
|
(deref (::data/value ref))
|
||||||
|
(throw (ex-info "Cannot deref something that is not a ref" {}))
|
||||||
|
))})
|
||||||
|
|
||||||
|
(def set!- {:name "set!"
|
||||||
|
::data/type ::data/clj
|
||||||
|
:body (fn [ref value]
|
||||||
|
(if (::data/ref ref)
|
||||||
|
(reset! (::data/value ref) value)
|
||||||
|
(throw (ex-info "Cannot set! something that is not a ref" {}))
|
||||||
|
))})
|
||||||
|
|
||||||
(declare show)
|
(declare show)
|
||||||
|
|
||||||
(defn- show-vector [v]
|
(defn- show-vector [v]
|
||||||
|
@ -66,4 +83,7 @@
|
||||||
"inc" inc-
|
"inc" inc-
|
||||||
"dec" dec-
|
"dec" dec-
|
||||||
"not" not
|
"not" not
|
||||||
"show" show})
|
"show" show
|
||||||
|
"deref" deref-
|
||||||
|
"set!" set!-
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user