Check if a variable is assignable, based on whether it is in the innermost scope and based on the variables being currently affected.
(atc-var-assignablep var innermostp affect) → yes/no
A variable may be destructively assigned to if any of the following conditions apply: (i) it is declared in the innermost scope, because in that case it cannot be accessed after exiting the scope; (ii) it is being affected, because in that case its modified value is returned and used in subsequent code; (iii) no variable is being affected, because in that case there is no subsequent code.
Function:
(defun atc-var-assignablep (var innermostp affect) (declare (xargs :guard (and (symbolp var) (booleanp innermostp) (symbol-listp affect)))) (let ((__function__ 'atc-var-assignablep)) (declare (ignorable __function__)) (or innermostp (and (member-eq var affect) t) (null affect))))
Theorem:
(defthm booleanp-of-atc-var-assignablep (implies (booleanp innermostp) (b* ((yes/no (atc-var-assignablep var innermostp affect))) (booleanp yes/no))) :rule-classes :rewrite)