Better handling of calling a non-function
This commit is contained in:
parent
297a7f2111
commit
dd9b89b5e1
1 changed files with 31 additions and 25 deletions
|
|
@ -160,6 +160,10 @@
|
|||
|
||||
(define-lookup)
|
||||
|
||||
(defmacro one-of [x elements]
|
||||
`(let [x# ~x]
|
||||
(case x# (~@elements) x# nil)))
|
||||
|
||||
(defn resolve-symbol [expr]
|
||||
(let [n (name expr)]
|
||||
(if (str/starts-with? n "'")
|
||||
|
|
@ -180,6 +184,8 @@
|
|||
(into (empty expr) (map i expr))
|
||||
(seq? expr)
|
||||
(if-let [f (first expr)]
|
||||
(let [f (or (one-of f [if when and or -> ->>])
|
||||
(interpret f in))]
|
||||
(if-let [v (var-lookup f)]
|
||||
(apply-fn v i (rest expr))
|
||||
(case f
|
||||
|
|
@ -204,7 +210,7 @@
|
|||
(apply-fn (resolve-symbol f) i (rest expr))
|
||||
(ifn? f)
|
||||
(apply-fn f i (rest expr))
|
||||
:else nil)))
|
||||
:else (throw (Exception. (format "Cannot call %s as a function." (pr-str f))))))))
|
||||
expr)
|
||||
;; read fn passed as higher order fn, still needs input
|
||||
(-> expr meta ::fn)
|
||||
|
|
|
|||
Loading…
Reference in a new issue