Compare commits

..

3 Commits

Author SHA1 Message Date
Scott Richmond
533a40bd45 runtime errors should return strings, not buffers 2024-06-07 16:41:11 -04:00
Scott Richmond
1fff319bb6 fix random bugs 2024-06-07 16:40:37 -04:00
Scott Richmond
de647097b7 0.1.9 2024-06-07 15:44:43 -04:00
4 changed files with 13 additions and 13 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@ludus/ludus-js-pure",
"version": "0.1.8",
"version": "0.1.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@ludus/ludus-js-pure",
"version": "0.1.8",
"version": "0.1.9",
"license": "GPL-3.0",
"devDependencies": {
"shadow-cljs": "^2.26.0",

View File

@ -1,6 +1,6 @@
{
"name": "@ludus/ludus-js-pure",
"version": "0.1.8",
"version": "0.1.9",
"description": "A Ludus interpreter in a pure JS function.",
"type": "module",
"main": "build/ludus.mjs",

View File

@ -910,8 +910,8 @@ fn dist {
fn random {
"Returns a random number. With zero arguments, returns a random number between 0 (inclusive) and 1 (exclusive). With one argument, returns a random number between 0 and n. With two arguments, returns a random number between m and n. Alternately, given a list, it returns a random member of that list."
() -> base :random ()
(n as :number) -> base :random (n)
(m as :number, n as :number) -> add (m, random (n))
(n as :number) -> mult (n, random ())
(m as :number, n as :number) -> add (m, random (sub (n, m)))
(l as :list) -> {
let i = do l > count > random > floor
at (l, i)

View File

@ -24,13 +24,13 @@
(set (out :errors) (scanned :errors))
(each err (scanned :errors)
(e/scan-error err))
(break (j/encode out)))
(break (-> out j/encode string)))
(def parsed (p/parse scanned))
(when (any? (parsed :errors))
(set (out :errors) (parsed :errors))
(each err (parsed :errors)
(e/parse-error err))
(break (j/encode out)))
(break (-> out j/encode string)))
(def validated (v/valid parsed ctx))
(when (any? (validated :errors))
(set (out :errors) (validated :errors))
@ -43,7 +43,7 @@
([err]
(e/runtime-error err)
(set (out :errors) [err])
(break (j/encode out))))
(break (-> out j/encode string))))
(setdyn :out stdout)
(set (out :result) (b/show result))
(var post @{})
@ -51,9 +51,9 @@
(set post (i/interpret prelude/post/ast ctx))
([err] (e/runtime-error err)))
(set (out :draw) (post :draw))
(string (j/encode out)))
(-> out j/encode string))
(-> (ludus `
random (1, 3)
`) j/decode)
(ludus `
let foo = 42
"{foo} bar baz"
`)