Get stuff running again, fix missing nil pattern, play wtih unwrap, default

This commit is contained in:
Scott Richmond 2023-05-27 18:05:43 -04:00
parent 3a7f86e401
commit fdaf1068d3
4 changed files with 43 additions and 19 deletions

View File

@ -4,15 +4,8 @@
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"} :url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.11.1"] :dependencies [[org.clojure/clojure "1.11.1"]
<<<<<<< HEAD
[babashka/fs "0.1.6"] [babashka/fs "0.1.6"]
[quil "4.0.0-SNAPSHOT"]] [quil "4.0.0-SNAPSHOT"]]
||||||| 1c2ab51
[babashka/fs "0.1.6"]]
=======
[babashka/fs "0.1.6"]
[quil "4.0.0-SNAPSHOT-1"]]
>>>>>>> 55d76f6854bf67119873d98e2c9c18d8390ab90a
:plugins [[lein-cljfmt "0.8.0"]] :plugins [[lein-cljfmt "0.8.0"]]
:repl-options {:init-ns ludus.core} :repl-options {:init-ns ludus.core}
:main ludus.core :main ludus.core

29
sandbox.ld Normal file
View File

@ -0,0 +1,29 @@
fn unwrap {
((:some, value)) -> value
((:ok, value)) -> value
}
fn default (default_value) -> fn (maybe) -> match maybe with {
(:ok, value) -> value
(:err, _) -> default_value
nil -> default_value
value -> value
}
fn some (value) -> (:some, value)
fn ok (value) -> (:ok, value)
let foo = unwrap ((:ok, 42))
print (:foo, foo)
let bar = unwrap ((:some, 23))
print (:bar, bar)
let baz = do 69 > default (12) > print (:baz, _)
let quux = do nil > default (12) > print (:quux, _)
unwrap ((:err, "message"))

View File

@ -155,8 +155,8 @@
:token (current origin) :token (current origin)
:partial (contains-placeholder? ms)}] :partial (contains-placeholder? ms)}]
(if (unary-placeholder? ast) (if (unary-placeholder? ast)
(panic parser "You may not use a placeholder in a tuple of length 1. You may only partially apply functions that take more than one argument.") (panic parser "You may not use a placeholder in a tuple of length 1. You may only partially apply functions that take more than one argument.")
(assoc (advance parser) ::ast ast))) (assoc (advance parser) ::ast ast)))
(::token/comma ::token/newline) (::token/comma ::token/newline)
(recur (recur
@ -684,7 +684,7 @@
::token/word (parse-word parser) ::token/word (parse-word parser)
(::token/number ::token/string ::token/keyword) (parse-atom parser) (::token/number ::token/string ::token/keyword ::token/nil) (parse-atom parser)
::token/lparen (parse-tuple-pattern parser) ::token/lparen (parse-tuple-pattern parser)
@ -1224,7 +1224,7 @@
(parser) (parser)
(parse-script))) (parse-script)))
(do (comment
(def my-source " (def my-source "
data Foo {foo, bar} data Foo {foo, bar}
data Bar as { data Bar as {

View File

@ -2,7 +2,8 @@
(:require (:require
[ludus.data :as data] [ludus.data :as data]
[ludus.show :as show] [ludus.show :as show]
[ludus.draw :as d])) ;[ludus.draw :as d]
))
;; TODO: make eq, and, or special forms that short-circuit ;; TODO: make eq, and, or special forms that short-circuit
;; Right now, they evaluate all their args ;; Right now, they evaluate all their args
@ -94,13 +95,14 @@
::data/type ::data/clj ::data/type ::data/clj
:body get}) :body get})
(def draw {:name "draw" (comment
::data/type ::data/clj (def draw {:name "draw"
:body draw/ludus-draw}) ::data/type ::data/clj
:body draw/ludus-draw})
(def draw {:name "draw" (def draw {:name "draw"
::data/type ::data/clj ::data/type ::data/clj
:body d/draw}) :body d/draw}))
(def prelude {"eq" eq (def prelude {"eq" eq
"add" add "add" add
@ -120,5 +122,5 @@
"assoc" assoc- "assoc" assoc-
"conj" conj- "conj" conj-
"get" get- "get" get-
"draw" draw ;"draw" draw
}) })