Bugfixes.
This commit is contained in:
parent
7c30b6259b
commit
5c8ba725a9
48
sandbox.ld
48
sandbox.ld
|
@ -1,3 +1,47 @@
|
||||||
import "foo.ld" as foo
|
fn map {
|
||||||
|
(f) -> fn mapper (xs) -> map (f, xs)
|
||||||
|
(f, xs) -> {
|
||||||
|
let n = count (xs)
|
||||||
|
loop (0, []) with (i, ys) -> if eq (i, n)
|
||||||
|
then ys
|
||||||
|
else recur (inc (i), conj (ys, f (nth (i, xs))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print ("Hello, world!", foo)
|
fn reduce {
|
||||||
|
(f) -> fn reducer {
|
||||||
|
(xs) -> reduce (f, xs)
|
||||||
|
(xs, init) -> reduce (f, xs, init)
|
||||||
|
}
|
||||||
|
(f, xs) -> {
|
||||||
|
let first_x = first (xs)
|
||||||
|
let more_xs = rest (xs)
|
||||||
|
reduce (f, more_xs, first_x)
|
||||||
|
}
|
||||||
|
(f, xs, init) -> {
|
||||||
|
let n = count (xs)
|
||||||
|
loop (0, init) with (i, acc) -> if eq (i, n)
|
||||||
|
then acc
|
||||||
|
else {
|
||||||
|
let curr = nth (i, xs)
|
||||||
|
let next = f (acc, curr)
|
||||||
|
recur (inc (i), next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn filter {
|
||||||
|
(f) -> fn filterer (xs) -> filter (f, xs)
|
||||||
|
(f, xs) -> {
|
||||||
|
let n = count (xs)
|
||||||
|
loop (0, []) with (i, ys) -> when {
|
||||||
|
eq (i, n) -> ys
|
||||||
|
f (nth (i, xs)) -> recur (inc (i), conj (ys, nth (i, xs)))
|
||||||
|
else -> recur (inc (i), ys)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let xs = [1, 2, 3]
|
||||||
|
|
||||||
|
filter (gte (_, 2) ,xs)
|
|
@ -23,7 +23,7 @@
|
||||||
(if (p/fail? parsed)
|
(if (p/fail? parsed)
|
||||||
(do
|
(do
|
||||||
(println "I found some parsing errors!")
|
(println "I found some parsing errors!")
|
||||||
(println p/err-msg parsed)
|
(println (p/err-msg parsed))
|
||||||
(System/exit 66))
|
(System/exit 66))
|
||||||
(let [interpreted (interpreter/interpret source file parsed)]
|
(let [interpreted (interpreter/interpret source file parsed)]
|
||||||
(println (show/show interpreted))
|
(println (show/show interpreted))
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
[ludus.scanner :as s]))
|
[ludus.scanner :as s]))
|
||||||
|
|
||||||
(def source
|
(def source
|
||||||
"when x is { true -> true }
|
"(1 2)
|
||||||
"
|
"
|
||||||
)
|
)
|
||||||
|
|
||||||
(def tokens (-> source s/scan :tokens))
|
(def tokens (-> source s/scan :tokens))
|
||||||
|
|
||||||
(def result (p/apply-parser g/when-expr tokens))
|
(def result (p/apply-parser g/script tokens))
|
||||||
|
|
||||||
(-> result :data)
|
(-> result :data)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
(-> node
|
(-> node
|
||||||
(report)
|
(report)
|
||||||
(dissoc
|
(dissoc
|
||||||
:status
|
;:status
|
||||||
:remaining
|
:remaining
|
||||||
:token)
|
:token)
|
||||||
(update :data #(into [] (map clean) %)))
|
(update :data #(into [] (map clean) %)))
|
||||||
|
|
|
@ -37,6 +37,22 @@
|
||||||
::data/type ::data/clj
|
::data/type ::data/clj
|
||||||
:body /})
|
:body /})
|
||||||
|
|
||||||
|
(def gt {:name "gt"
|
||||||
|
::data/type ::data/clj
|
||||||
|
:body >})
|
||||||
|
|
||||||
|
(def gte {:name "gte"
|
||||||
|
::data/type ::data/clj
|
||||||
|
:body >=})
|
||||||
|
|
||||||
|
(def lt {:name "lt"
|
||||||
|
::data/type ::data/clj
|
||||||
|
:body <})
|
||||||
|
|
||||||
|
(def lte {:name "lte"
|
||||||
|
::data/type ::data/clj
|
||||||
|
:body <=})
|
||||||
|
|
||||||
(def inc- {:name "inc"
|
(def inc- {:name "inc"
|
||||||
::data/type ::data/clj
|
::data/type ::data/clj
|
||||||
:body inc})
|
:body inc})
|
||||||
|
@ -114,10 +130,17 @@
|
||||||
|
|
||||||
(def nth- {:name "nth"
|
(def nth- {:name "nth"
|
||||||
::data/type ::data/clj
|
::data/type ::data/clj
|
||||||
:body (fn [i, xs]
|
:body (fn
|
||||||
(if (contains? xs (inc i))
|
([i, xs]
|
||||||
(nth xs (inc i))
|
(cond
|
||||||
nil))})
|
(> 0 i) nil
|
||||||
|
(contains? xs (inc i)) (nth xs (inc i))
|
||||||
|
:else nil))
|
||||||
|
([i, xs, default]
|
||||||
|
(cond
|
||||||
|
(> 0 i) default
|
||||||
|
(contains? xs (inc i)) (nth xs (inc i))
|
||||||
|
:else default)))})
|
||||||
|
|
||||||
(defn get-type [value]
|
(defn get-type [value]
|
||||||
(let [t (type value)]
|
(let [t (type value)]
|
||||||
|
@ -168,6 +191,10 @@
|
||||||
(println "Args: " fn-args)
|
(println "Args: " fn-args)
|
||||||
(apply called fn-args)))})
|
(apply called fn-args)))})
|
||||||
|
|
||||||
|
(def count- {:name "count"
|
||||||
|
::data/type ::data/clj
|
||||||
|
:body (fn [xs] (dec (count xs)))})
|
||||||
|
|
||||||
(def prelude {
|
(def prelude {
|
||||||
"id" id
|
"id" id
|
||||||
"eq" eq
|
"eq" eq
|
||||||
|
@ -176,6 +203,10 @@
|
||||||
"sub" sub
|
"sub" sub
|
||||||
"mult" mult
|
"mult" mult
|
||||||
"div" div
|
"div" div
|
||||||
|
"gt" gt
|
||||||
|
"gte" gte
|
||||||
|
"lt" lt
|
||||||
|
"lte" lte
|
||||||
"inc" inc-
|
"inc" inc-
|
||||||
"dec" dec-
|
"dec" dec-
|
||||||
"not" not
|
"not" not
|
||||||
|
@ -193,4 +224,5 @@
|
||||||
"first" first-
|
"first" first-
|
||||||
"rest" rest-
|
"rest" rest-
|
||||||
"nth" nth-
|
"nth" nth-
|
||||||
|
"count" count-
|
||||||
})
|
})
|
|
@ -25,7 +25,7 @@
|
||||||
"ref" :ref ;; impl
|
"ref" :ref ;; impl
|
||||||
"then" :then ;; impl
|
"then" :then ;; impl
|
||||||
"true" :true ;; impl -> literal word
|
"true" :true ;; impl -> literal word
|
||||||
;"with" :with ;; impl
|
"with" :with ;; impl
|
||||||
|
|
||||||
;; actor model/concurrency
|
;; actor model/concurrency
|
||||||
"receive" :receive
|
"receive" :receive
|
||||||
|
|
Loading…
Reference in New Issue
Block a user