Improve prelude

This commit is contained in:
Scott Richmond 2023-06-01 13:11:06 -06:00
parent a6ef6522c0
commit c179325719
2 changed files with 31 additions and 4 deletions

View File

@ -963,7 +963,9 @@
(do
(def source "
let xs = [1, 2, 3]
let ys = #{:a 1, :b 2}
get (:c, ys)
")
(println "")

View File

@ -92,12 +92,36 @@
(def get- {:name "get"
::data/type ::data/clj
:body get})
:body (fn
([key, map]
(if (map? map)
(get map key)
nil))
([key, map, default]
(if (map? map)
(get map key default)
default)))})
(def draw {:name "draw"
::data/type ::data/clj
:body d/ludus-draw})
(def first- {:name "first"
::data/type ::data/clj
:body (fn [v] (second v))})
(def rest- {:name "rest"
::data/type ::data/clj
:body (fn [v]
(into [::data/list] (nthrest v 2)))})
(def nth- {:name "nth"
::data/type ::data/clj
:body (fn [i, xs]
(if (contains? xs (inc i))
(nth xs (inc i))
nil))})
(defn get-type [value]
(let [t (type value)]
(cond
@ -149,8 +173,6 @@
(def prelude {
"id" id
"foo" :foo
"bar" :bar
"eq" eq
"add" add
"print" print-
@ -172,4 +194,7 @@
"draw" draw
"type" type-
"clj" clj
"first" first-
"rest" rest-
"nth" nth-
})