From f93eacf5f5918569178ca67f0bea07b6d191be65 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 3 Apr 2022 17:03:22 -0400 Subject: [PATCH] Fix keyword function calling --- src/ludus/interpreter.clj | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ludus/interpreter.clj b/src/ludus/interpreter.clj index 26df16d..d00488f 100644 --- a/src/ludus/interpreter.clj +++ b/src/ludus/interpreter.clj @@ -145,14 +145,16 @@ (recur (first clauses) (rest clauses)))) (throw (ex-info "Match Error: No match found" {:fn-name (:name fn)}))))) + + ;; TODO: clean this up + ;; TODO: error with a passed tuple longer than 1 (if (= clojure.lang.Keyword (type fn)) - (if (::data/struct passed) - (if (contains? map fn) - (fn map) + (if (::data/struct (second passed)) + (if (contains? (second passed) fn) + (fn (second passed)) (throw (ex-info (str "Struct error: no member at " fn) {}))) - (get map fn)) - (throw (ex-info "I don't know how to call that" {:fn fn})) - )))) + (get (second passed) fn)) + (throw (ex-info "I don't know how to call that" {:fn fn})))))) ;; TODO: add placeholder partial application (defn- interpret-synthetic-term [prev-value curr ctx] @@ -229,7 +231,7 @@ (run! #(interpret % ctx) inner) (interpret last ctx)) - ;; note that, excepting a tuple, + ;; note that, excepting tuples and structs, ;; runtime representations are bare ;; tuples are vectors with a special first member ::ast/tuple @@ -258,9 +260,9 @@ (def source " - fn call (callable, target) -> callable (target) + fn call (callable, target, thing) -> callable (target, thing) fn id (x) -> x - call (:foo, 12) + call (:foo, nil, nil) ") @@ -282,6 +284,8 @@ * if-let pattern * improve panics * add location info for panics + * refactor calling keywords + * refactor accessing structs vs. hashes ")