ref -> box; fix box representations; add ds modifying functions to base
This commit is contained in:
parent
6cc7f045a2
commit
fa5e298d94
|
@ -68,7 +68,7 @@
|
||||||
:list (string "[" (stringify x) "]")
|
:list (string "[" (stringify x) "]")
|
||||||
:dict (string "#{" (stringify x) "}")
|
:dict (string "#{" (stringify x) "}")
|
||||||
:set (string "${" (stringify x) "}")
|
:set (string "${" (stringify x) "}")
|
||||||
:ref (string "ref " (x :name) "{" (x :value) "}")
|
:ref (string "box " (x :name) " [ " (stringify x) " ]")
|
||||||
:pkg (show-pkg x)
|
:pkg (show-pkg x)
|
||||||
(stringify x)))
|
(stringify x)))
|
||||||
|
|
||||||
|
@ -97,14 +97,25 @@
|
||||||
(print (string/join patterns " "))
|
(print (string/join patterns " "))
|
||||||
(print doc))
|
(print doc))
|
||||||
|
|
||||||
|
(defn- conj!-set [sett value]
|
||||||
|
(set (sett value) true)
|
||||||
|
sett)
|
||||||
|
|
||||||
(defn- conj-set [sett value]
|
(defn- conj-set [sett value]
|
||||||
(def new (merge sett))
|
(def new (merge sett))
|
||||||
(set (new value) true)
|
(conj!-set new value))
|
||||||
new)
|
|
||||||
|
(defn- conj!-list [list value]
|
||||||
|
(array/push list value))
|
||||||
|
|
||||||
(defn- conj-list [list value]
|
(defn- conj-list [list value]
|
||||||
(def new (array/slice list))
|
(def new (array/slice list))
|
||||||
(array/push new value))
|
(conj!-list new value))
|
||||||
|
|
||||||
|
(defn conj! [x value]
|
||||||
|
(case (ludus/type x)
|
||||||
|
:list (conj!-list x value)
|
||||||
|
:set (conj!-set x value)))
|
||||||
|
|
||||||
(defn conj [x value]
|
(defn conj [x value]
|
||||||
(case (ludus/type x)
|
(case (ludus/type x)
|
||||||
|
@ -112,14 +123,26 @@
|
||||||
:set (conj-set x value)
|
:set (conj-set x value)
|
||||||
(error (string "cannot conj onto " (show x)))))
|
(error (string "cannot conj onto " (show x)))))
|
||||||
|
|
||||||
|
(defn disj! [sett value]
|
||||||
|
(set (sett value) nil)
|
||||||
|
sett)
|
||||||
|
|
||||||
(defn disj [sett value]
|
(defn disj [sett value]
|
||||||
(def new (merge sett))
|
(def new (merge sett))
|
||||||
(set (new value) nil)
|
(set (new value) nil)
|
||||||
new)
|
new)
|
||||||
|
|
||||||
|
(defn assoc! [dict key value]
|
||||||
|
(set (dict key) value)
|
||||||
|
dict)
|
||||||
|
|
||||||
(defn assoc [dict key value]
|
(defn assoc [dict key value]
|
||||||
(merge dict {key value}))
|
(merge dict {key value}))
|
||||||
|
|
||||||
|
(defn dissoc! [dict key]
|
||||||
|
(set (dict key) nil)
|
||||||
|
dict)
|
||||||
|
|
||||||
(defn dissoc [dict key]
|
(defn dissoc [dict key]
|
||||||
(def new (merge dict))
|
(def new (merge dict))
|
||||||
(set (new key) nil)
|
(set (new key) nil)
|
||||||
|
@ -147,15 +170,15 @@
|
||||||
(pp x)
|
(pp x)
|
||||||
x)
|
x)
|
||||||
|
|
||||||
(defn concat [x y]
|
(defn concat [x y & zs]
|
||||||
(case (ludus/type x)
|
(case (ludus/type x)
|
||||||
:string (string x y)
|
:string (string x y ;zs)
|
||||||
:list (array/concat @[] x y)
|
:list (array/concat @[] x y ;zs)
|
||||||
:set (merge x y)))
|
:set (merge x y ;zs)))
|
||||||
|
|
||||||
(defn deref [x] (get x :value))
|
(defn unbox [x] (get x :^value))
|
||||||
|
|
||||||
(defn set! [x] (set (x :value) x))
|
(defn store! [x] (set (x :^value) x))
|
||||||
|
|
||||||
(def ctx {
|
(def ctx {
|
||||||
"print!" print!
|
"print!" print!
|
||||||
|
@ -182,10 +205,14 @@
|
||||||
"doc!" doc!
|
"doc!" doc!
|
||||||
"concat" concat
|
"concat" concat
|
||||||
"conj" conj
|
"conj" conj
|
||||||
|
"conj!" conj!
|
||||||
"disj" disj
|
"disj" disj
|
||||||
|
"disj!" disj!
|
||||||
"push" array/push
|
"push" array/push
|
||||||
"assoc" assoc
|
"assoc" assoc
|
||||||
|
"assoc!" assoc!
|
||||||
"dissoc" dissoc
|
"dissoc" dissoc
|
||||||
|
"dissoc!" dissoc!
|
||||||
"get" ludus/get
|
"get" ludus/get
|
||||||
"nth" ludus/get
|
"nth" ludus/get
|
||||||
"first" first
|
"first" first
|
||||||
|
@ -205,8 +232,8 @@
|
||||||
"ceil" math/ceil
|
"ceil" math/ceil
|
||||||
"round" math/round
|
"round" math/round
|
||||||
"range" range
|
"range" range
|
||||||
"deref" deref
|
"unbox" unbox
|
||||||
"set!" set!
|
"store!" store!
|
||||||
})
|
})
|
||||||
|
|
||||||
(def base (let [b @{}]
|
(def base (let [b @{}]
|
||||||
|
|
|
@ -340,8 +340,9 @@
|
||||||
(defn- ref [ast ctx]
|
(defn- ref [ast ctx]
|
||||||
(def {:data value-ast :name name} ast)
|
(def {:data value-ast :name name} ast)
|
||||||
(def value (interpret value-ast ctx))
|
(def value (interpret value-ast ctx))
|
||||||
(set (ctx name) @{:^type :ref :^value value :^name name})
|
(def box @{:^type :ref :^value value :name name})
|
||||||
value)
|
(set (ctx name) box)
|
||||||
|
box)
|
||||||
|
|
||||||
(defn- repeatt [ast ctx]
|
(defn- repeatt [ast ctx]
|
||||||
(def [times-ast body] (ast :data))
|
(def [times-ast body] (ast :data))
|
||||||
|
@ -633,8 +634,7 @@
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(set source `
|
(set source `
|
||||||
fn myadd (x, y) -> add (x, y)
|
box foo = :bar
|
||||||
myadd (1, _) (2)
|
|
||||||
`)
|
`)
|
||||||
(def result (run))
|
(def result (run))
|
||||||
(b/show result)
|
(b/show result)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"List of Ludus reserved words."
|
"List of Ludus reserved words."
|
||||||
## see ludus-spec repo for more info
|
## see ludus-spec repo for more info
|
||||||
{"as" :as ## impl
|
{"as" :as ## impl
|
||||||
|
"box" :ref
|
||||||
"do" :do ## impl
|
"do" :do ## impl
|
||||||
"else" :else ## impl
|
"else" :else ## impl
|
||||||
"false" :false ## impl -> literal word
|
"false" :false ## impl -> literal word
|
||||||
|
@ -16,7 +17,6 @@
|
||||||
"panic!" :panic ## impl (should _not_ be a function)
|
"panic!" :panic ## impl (should _not_ be a function)
|
||||||
"pkg" :pkg
|
"pkg" :pkg
|
||||||
"recur" :recur ## impl
|
"recur" :recur ## impl
|
||||||
"ref" :ref ## impl
|
|
||||||
"then" :then ## impl
|
"then" :then ## impl
|
||||||
"true" :true ## impl -> literal word
|
"true" :true ## impl -> literal word
|
||||||
"use" :use ## wip
|
"use" :use ## wip
|
||||||
|
|
Loading…
Reference in New Issue
Block a user