From fdaf1068d35cd9c368254a9b1a42296c49ffbcb4 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sat, 27 May 2023 18:05:43 -0400 Subject: [PATCH] Get stuff running again, fix missing nil pattern, play wtih unwrap, default --- project.clj | 7 ------- sandbox.ld | 29 +++++++++++++++++++++++++++++ src/ludus/parser.clj | 8 ++++---- src/ludus/prelude.clj | 18 ++++++++++-------- 4 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 sandbox.ld diff --git a/project.clj b/project.clj index a9696ab..b040fc4 100644 --- a/project.clj +++ b/project.clj @@ -4,15 +4,8 @@ :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/"} :dependencies [[org.clojure/clojure "1.11.1"] -<<<<<<< HEAD [babashka/fs "0.1.6"] [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"]] :repl-options {:init-ns ludus.core} :main ludus.core diff --git a/sandbox.ld b/sandbox.ld new file mode 100644 index 0000000..7cdc4ee --- /dev/null +++ b/sandbox.ld @@ -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")) diff --git a/src/ludus/parser.clj b/src/ludus/parser.clj index 9b1612e..32eec68 100644 --- a/src/ludus/parser.clj +++ b/src/ludus/parser.clj @@ -155,8 +155,8 @@ :token (current origin) :partial (contains-placeholder? ms)}] (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.") - (assoc (advance parser) ::ast 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.") + (assoc (advance parser) ::ast ast))) (::token/comma ::token/newline) (recur @@ -684,7 +684,7 @@ ::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) @@ -1224,7 +1224,7 @@ (parser) (parse-script))) -(do +(comment (def my-source " data Foo {foo, bar} data Bar as { diff --git a/src/ludus/prelude.clj b/src/ludus/prelude.clj index 4936f0a..575bb19 100644 --- a/src/ludus/prelude.clj +++ b/src/ludus/prelude.clj @@ -2,7 +2,8 @@ (:require [ludus.data :as data] [ludus.show :as show] - [ludus.draw :as d])) + ;[ludus.draw :as d] + )) ;; TODO: make eq, and, or special forms that short-circuit ;; Right now, they evaluate all their args @@ -94,13 +95,14 @@ ::data/type ::data/clj :body get}) -(def draw {:name "draw" - ::data/type ::data/clj - :body draw/ludus-draw}) +(comment + (def draw {:name "draw" + ::data/type ::data/clj + :body draw/ludus-draw}) -(def draw {:name "draw" - ::data/type ::data/clj - :body d/draw}) + (def draw {:name "draw" + ::data/type ::data/clj + :body d/draw})) (def prelude {"eq" eq "add" add @@ -120,5 +122,5 @@ "assoc" assoc- "conj" conj- "get" get- - "draw" draw + ;"draw" draw }) \ No newline at end of file