Fix keyword function calling

This commit is contained in:
Scott Richmond 2022-04-03 17:03:22 -04:00
parent 7a4034d920
commit f93eacf5f5

View File

@ -145,14 +145,16 @@
(recur (first clauses) (rest clauses)))) (recur (first clauses) (rest clauses))))
(throw (ex-info "Match Error: No match found" {:fn-name (:name fn)}))))) (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 (= clojure.lang.Keyword (type fn))
(if (::data/struct passed) (if (::data/struct (second passed))
(if (contains? map fn) (if (contains? (second passed) fn)
(fn map) (fn (second passed))
(throw (ex-info (str "Struct error: no member at " fn) {}))) (throw (ex-info (str "Struct error: no member at " fn) {})))
(get map fn)) (get (second passed) fn))
(throw (ex-info "I don't know how to call that" {:fn fn})) (throw (ex-info "I don't know how to call that" {:fn fn}))))))
))))
;; TODO: add placeholder partial application ;; TODO: add placeholder partial application
(defn- interpret-synthetic-term [prev-value curr ctx] (defn- interpret-synthetic-term [prev-value curr ctx]
@ -229,7 +231,7 @@
(run! #(interpret % ctx) inner) (run! #(interpret % ctx) inner)
(interpret last ctx)) (interpret last ctx))
;; note that, excepting a tuple, ;; note that, excepting tuples and structs,
;; runtime representations are bare ;; runtime representations are bare
;; tuples are vectors with a special first member ;; tuples are vectors with a special first member
::ast/tuple ::ast/tuple
@ -258,9 +260,9 @@
(def source " (def source "
fn call (callable, target) -> callable (target) fn call (callable, target, thing) -> callable (target, thing)
fn id (x) -> x fn id (x) -> x
call (:foo, 12) call (:foo, nil, nil)
") ")
@ -282,6 +284,8 @@
* if-let pattern * if-let pattern
* improve panics * improve panics
* add location info for panics * add location info for panics
* refactor calling keywords
* refactor accessing structs vs. hashes
") ")