Called KW enforce one arg

This commit is contained in:
Scott Richmond 2022-04-03 19:13:54 -04:00
parent f93eacf5f5
commit b8e7777841
2 changed files with 20 additions and 10 deletions

View File

@ -149,11 +149,14 @@
;; TODO: clean this up
;; TODO: error with a passed tuple longer than 1
(if (= clojure.lang.Keyword (type fn))
(if (::data/struct (second passed))
(if (contains? (second passed) fn)
(fn (second passed))
(throw (ex-info (str "Struct error: no member at " fn) {})))
(get (second passed) fn))
(if (= 2 (count passed))
(let [target (second passed) kw fn]
(if (::data/struct target)
(if (contains? target kw)
(kw target)
(throw (ex-info (str "Struct error: no member at " kw) {})))
(kw target)))
(throw (ex-info "Called keywords take a single argument" {})))
(throw (ex-info "I don't know how to call that" {:fn fn}))))))
;; TODO: add placeholder partial application
@ -260,9 +263,9 @@
(def source "
fn call (callable, target, thing) -> callable (target, thing)
fn id (x) -> x
call (:foo, nil, nil)
fn call (f, t) -> f (t)
call (:foo, #{:foo 23})
")

View File

@ -606,7 +606,14 @@
(do
(def pp pp/pprint)
(def source "@{:foo :bar, :bar 42}")
(def source "
fn maybe_foo (mf) -> if eq (mf, :foo)
then (:ok, :foo)
else (:error, mf)
")
(def lexed (scanner/scan source))
(def tokens (:tokens lexed))
(def p (parser tokens))
@ -618,7 +625,7 @@
(println "*** *** NEW PARSE *** ***")
(-> p
(parse-expr)
(parse-script)
(::ast)
(pp)))