This commit is contained in:
Scott Richmond 2024-10-23 17:27:32 -04:00
parent 54e7597b33
commit bb0aaef060
6 changed files with 31 additions and 8 deletions

Binary file not shown.

View File

@ -6489,7 +6489,7 @@ var __emscripten_stack_alloc = (a0) => (__emscripten_stack_alloc = wasmExports['
var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])(); var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])();
var ___cxa_is_pointer_type = createExportWrapper('__cxa_is_pointer_type', 1); var ___cxa_is_pointer_type = createExportWrapper('__cxa_is_pointer_type', 1);
var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji', 5); var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji', 5);
var ___emscripten_embedded_file_data = Module['___emscripten_embedded_file_data'] = 1816104; var ___emscripten_embedded_file_data = Module['___emscripten_embedded_file_data'] = 1819008;
function invoke_i(index) { function invoke_i(index) {
var sp = stackSave(); var sp = stackSave();
try { try {

Binary file not shown.

View File

@ -279,9 +279,10 @@ fn concat {
} }
fn set { fn set {
"Takes an ordered collection--list or tuple--and turns it into a set." "Takes an ordered collection--list or tuple--and turns it into a set. Returns sets unharmed."
(xs as :list) -> fold (append, xs, ${}) (xs as :list) -> fold (append, xs, ${})
(xs as :tuple) -> do xs > list > set (xs as :tuple) -> do xs > list > set
(xs as :set) -> xs
} }
fn set? { fn set? {
@ -434,6 +435,11 @@ fn sentence {
(strs as :list) -> join (strs, " ") (strs as :list) -> join (strs, " ")
} }
fn to_number {
"Takes a string that presumably contains a representation of a number, and tries to give you back the number represented. Returns a result tuple."
(num as :string) -> base :to_number (num)
}
&&& boxes: mutable state and state changes &&& boxes: mutable state and state changes
fn box? { fn box? {
@ -1434,6 +1440,7 @@ pkg Prelude {
sum_of_squares & math sum_of_squares & math
tan & math tan & math
tau & math tau & math
to_number &strings numbers
trim & strings trim & strings
tuple? & tuples tuple? & tuples
turn/deg & math turn/deg & math

View File

@ -1,6 +1,8 @@
# A base library for Ludus # A base library for Ludus
# Only loaded in the prelude # Only loaded in the prelude
(import /src/scanner :as s)
(defn bool [x] (if (= :^nil x) nil x)) (defn bool [x] (if (= :^nil x) nil x))
(defn ludus/and [& args] (every? (map bool args))) (defn ludus/and [& args] (every? (map bool args)))
@ -248,6 +250,20 @@
([e] (break [:err e]))) ([e] (break [:err e])))
[:ok out]) [:ok out])
(defn to_number [str]
(when (string/find "&" str)
(break [:err (string "Could not parse `" str "` as a number")]))
(def scanned (s/scan (string/trim str)))
(when (< 0 (length (scanned :errors)))
(break [:err (string "Could not parse `" str "` as a number")]))
(def tokens (scanned :tokens))
(when (< 3 (length tokens))
(break [:err (string "Could not parse `" str "` as a number")]))
(def fst (first tokens))
(when (not= :number (fst :type))
(break [:err (string "Could not parse `" str "` as a number")]))
[:ok (fst :literal)])
(def ctx { (def ctx {
"add" + "add" +
"and" ludus/and "and" ludus/and
@ -304,6 +320,7 @@
"sub" - "sub" -
"tan" math/tan "tan" math/tan
"to_list" to_list "to_list" to_list
"to_number" to_number
"trim" string/trim "trim" string/trim
"triml" string/triml "triml" string/triml
"trimr" string/trimr "trimr" string/trimr
@ -317,4 +334,4 @@
(set (b (keyword k)) v)) (set (b (keyword k)) v))
b)) b))
(to_number " 123 a ")

View File

@ -349,8 +349,7 @@
(recur (-> scanner (scan-token) (next-token))))) (recur (-> scanner (scan-token) (next-token)))))
(recur (new-scanner source input))) (recur (new-scanner source input)))
(comment # (comment
# (do (do
(def source "add 1 2 () four") (def source " -123 ")
(scan source) (length ((scan source) :tokens)))
)