Cause an error if a value is not the name of an existing function, the name of an existing macro, or a lambda expression.
(ensure-function/macro/lambda x description error-erp error-val ctx state) → (mv erp val state)
If
In each of the above cases,
also return a new description of
The stobjs-in list of a lambda expression is calculated
in the same way as the stobjs-in list of a function,
using
If the translation of a lambda expression fails, the error message returned by check-user-lambda is incorporated into a larger error message. Since the message returned starts with the lambda expression, it can be incorporated into the larger message without capitalization concerns.
Function:
(defun ensure-function/macro/lambda (x description error-erp error-val ctx state) (declare (xargs :stobjs (state))) (declare (xargs :guard (msgp description))) (let ((__function__ 'ensure-function/macro/lambda)) (declare (ignorable __function__)) (b* ((wrld (w state))) (cond ((function-namep x wrld) (value (list x (stobjs-in x wrld) (stobjs-out x wrld) (msg "~@0, which is the function ~x1," description x)))) ((macro-namep x wrld) (b* ((args (macro-required-args x wrld)) (ulambda (cons 'lambda (cons args (cons (cons x args) 'nil)))) ((mv tlambda stobjs-out) (check-user-lambda ulambda wrld)) (stobjs-in (compute-stobj-flags args t nil wrld))) (value (list tlambda stobjs-in stobjs-out (msg "~@0, which is the lambda expression ~x1 ~ denoted by the macro ~x2," description ulambda x))))) ((symbolp x) (er-soft+ ctx error-erp error-val "~@0 must be a function name, a macro name, ~ or a lambda expression. ~ The symbol ~x1 is not the name of a function or macro." description x)) (t (b* (((mv tlambda/msg stobjs-out) (check-user-lambda x wrld)) ((when (msgp tlambda/msg)) (er-soft+ ctx error-erp error-val "~@0 must be a function name, a macro name, ~ or a lambda expression. ~ Since ~x1 is not a symbol, ~ it must be a lambda expression. ~ ~@2" description x tlambda/msg)) (tlambda tlambda/msg) (stobjs-in (compute-stobj-flags (lambda-formals tlambda) t nil wrld))) (value (list tlambda stobjs-in stobjs-out (msg "~@0, which is the lambda expression ~x1," description x)))))))))