partially applied functions don't kill validation

This commit is contained in:
Scott Richmond 2024-05-19 19:15:22 -04:00
parent 6bf4dde487
commit e5917c6284

View File

@ -338,14 +338,15 @@ Deferred until a later iteration of Ludus:
(defn- check-arity [validator] (defn- check-arity [validator]
(def ast (validator :ast)) (def ast (validator :ast))
(when (ast :partial) (break validator)) # (when (ast :partial) (break validator))
(def ctx (validator :ctx)) (def ctx (validator :ctx))
(def data (ast :data)) (def data (ast :data))
(def fn-word (first data)) (def fn-word (first data))
(def the-fn (resolve-name ctx (fn-word :data))) (def the-fn (resolve-name ctx (fn-word :data)))
(when (not the-fn) (break validator)) (when (not the-fn) (break validator))
(when (= :function (type the-fn)) (break validator)) (when (= :function (type the-fn)) (break validator))
(when (= :cfunction (type the-fn)) (break validator)) (when (= :cfunction (type the-fn) (break validator)))
(when (not= :fn (the-fn :type)) (break validator))
(print "fn name: " (the-fn :name)) (print "fn name: " (the-fn :name))
(def arities (the-fn :arities)) (def arities (the-fn :arities))
(print "arities: ") (print "arities: ")
@ -353,6 +354,7 @@ Deferred until a later iteration of Ludus:
(def args (get data 1)) (def args (get data 1))
(def num-args (length (args :data))) (def num-args (length (args :data)))
(print "called with #args " num-args) (print "called with #args " num-args)
(pp (get (validator :ctx) "bar"))
(when (has-key? arities num-args) (break validator)) (when (has-key? arities num-args) (break validator))
(def rest-arities (keys (arities :rest))) (def rest-arities (keys (arities :rest)))
(when (empty? rest-arities) (when (empty? rest-arities)
@ -629,17 +631,20 @@ Deferred until a later iteration of Ludus:
(set (validator :ctx) base-ctx) (set (validator :ctx) base-ctx)
(validate validator)) (validate validator))
(defn foo [] :foo) (import ./base :as b)
(def base {
"foo" foo
})
(do (do
# (comment # (comment
(def source ` (def source `
foo () fn foobar {
(:foo, :bar) -> true
(_, _) -> false
}
let bar = foobar (:foo, _)
bar (:bar, 2)
add ()
`) `)
(def scanned (s/scan source)) (def scanned (s/scan source))
(def parsed (p/parse scanned)) (def parsed (p/parse scanned))
(valid parsed base) (valid parsed b/ctx)
) )