Cause an error if a function or lambda expression does not have a given arity.
(ensure-function/lambda-arity stobjs-in n description error-erp error-val ctx state) → (mv erp val state)
The arity of the function or lambda expression is checked
by examining the stobjs-in list
of the function or lambda expression.
This error-checking function is useful
after calling ensure-function/macro/lambda
(which returns the stobjs-in list)
to handle functions and lambda expressions uniformly.
The
Function:
(defun ensure-function/lambda-arity (stobjs-in n description error-erp error-val ctx state) (declare (xargs :stobjs (state))) (declare (xargs :guard (and (symbol-listp stobjs-in) (natp n) (msgp description)))) (b* (((unless (= (len stobjs-in) n)) (er-soft+ ctx error-erp error-val "~@0 must take ~x1 ~@2." description n (if (= n 1) "argument" "arguments")))) (value nil)))
Theorem:
(defthm return-type-of-ensure-function/lambda-arity.erp (b* (((mv ?erp ?val ?state) (ensure-function/lambda-arity stobjs-in n description error-erp error-val ctx state))) (implies erp (equal erp error-erp))) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-ensure-function/lambda-arity.val (b* (((mv ?erp ?val ?state) (ensure-function/lambda-arity stobjs-in n description error-erp error-val ctx state))) (and (implies erp (equal val error-val)) (implies (and (not erp) error-erp) (not val)))) :rule-classes :rewrite)