From d924b5fa6f931bd5ee00495970cfe3288fd7b6a5 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 20 Mar 2022 16:15:07 -0400 Subject: [PATCH] Update notes --- src/ludus/interpreter.clj | 29 +++++++++++++++++++++++++---- src/ludus/parser.clj | 34 ++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/ludus/interpreter.clj b/src/ludus/interpreter.clj index f878e92..c157fa3 100644 --- a/src/ludus/interpreter.clj +++ b/src/ludus/interpreter.clj @@ -83,7 +83,7 @@ success (:success match)] (if success (swap! ctx update-ctx (:ctx match)) - (throw (new Exception (:reason match)))) + (throw (ex-info (:reason match) {}))) value )) @@ -144,7 +144,13 @@ :body + }) -(def prelude {"eq" eq "add" add}) +(def panic { + :name "panic" + ::ast/type ::ast/clj + :body (fn [msg & _] (throw (ex-info msg {}))) + }) + +(def prelude {"eq" eq "add" add "panic" panic}) (defn- call-fn [fn tuple ctx] (let [passed (interpret tuple ctx)] @@ -250,7 +256,8 @@ (def source " add (1, 2, 3) -") + + ") (println "") (println "****************************************") @@ -263,4 +270,18 @@ (::parser/ast) (interpret {}) (pp/pprint) - )) \ No newline at end of file + )) + +(comment " + + Left to do: + * if-let pattern + * improve panics + * add location info for panics + +") + + + + + diff --git a/src/ludus/parser.clj b/src/ludus/parser.clj index 7e01a5e..24e51b7 100644 --- a/src/ludus/parser.clj +++ b/src/ludus/parser.clj @@ -565,9 +565,7 @@ (do (def pp pp/pprint) - (def source "match foo with { - 0 -> foo - } + (def source "match foo with _ -> foo ") (def lexed (scanner/scan source)) @@ -589,18 +587,30 @@ (comment " Further thoughts/still to do: + * Functions + * anonymous, simple + * named, simple + * anonymous, complex? + * named, complex + * with docstrings? + * Cond expressions + * Loops + * Structs + * Namespaces + * Types (:|) + * Modules + * Add `as` clauses to patterns + * Add `when` clauses to patterns + * var/mut + * ref/swap + * Splats in lists, hashmaps, sets * AST nodes should include tokens/locations - at current, only atoms do this * Improve error handling in hashmap parsing - * - - Other quick thoughts: - - * Placeholders - - * Does this want to happen in parsing or in analysis? - - For future correctness checks: + * Consider error handling in match expressions + * Add treatment of ignored variables + * Placeholders + * How much in parser, how much in analysis? ")