From dfb0c7858c493e5f63731968d89ab4f5fc4090c1 Mon Sep 17 00:00:00 2001 From: prabhanshuguptagit Date: Mon, 1 Jul 2024 19:09:14 +0530 Subject: [PATCH] Handle error for undefined functions --- src/bean/errors.cljs | 4 ++++ src/bean/interpreter.cljs | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bean/errors.cljs b/src/bean/errors.cljs index b217415..375bd12 100644 --- a/src/bean/errors.cljs +++ b/src/bean/errors.cljs @@ -25,6 +25,10 @@ {:error (str "label \"" label-name "\" doesn't exist") :representation (str "label \"" label-name "\" doesn't exist")}) +(defn function-not-found [] + {:error "function not found" + :representation "function not found"}) + (defn spill-error [] {:error "Spill error" :representation "Spill error"}) diff --git a/src/bean/interpreter.cljs b/src/bean/interpreter.cljs index 98160a2..cff5501 100644 --- a/src/bean/interpreter.cljs +++ b/src/bean/interpreter.cljs @@ -154,9 +154,10 @@ (defn apply-f-args [sheet f args & [asts]] (let [fn-ast (:scalar f)] - (if (fn? fn-ast) - (apply-system-f sheet fn-ast args asts) - (apply-user-f sheet fn-ast args)))) + (cond + (:error f) f + (fn? fn-ast) (apply-system-f sheet fn-ast args asts) + :else (apply-user-f sheet fn-ast args)))) (defn apply-f [sheet f asts] (let [args (eval-asts sheet asts)]