Suffix a name with as many
(fresh-logical-name-with-$s-suffix name type names-to-avoid wrld) → (mv fresh-name updated-names-to-avoid)
The returned name can be used for a new function, macro, constant, etc.,
based on the
The resulting name may be the same as the argument,
with no
We use fresh-namep-msg-weak to check the freshness of names, which may miss names of functions in raw Lisp. But the more accurate check fresh-namep-msg, which takes into account names of functions in raw Lisp, is state-changing, which would therefore force this utility to be state-changing too. Thus, for now we use the weaker check, and avoid passing and returning state. If we encounter problems in the future, we will revise this utility, or introduce a new one.
Note that if the logical name is for a constant,
the
Since the ACL2 world is finite,
eventually we must find a fresh name,
with enough
Function:
(defun fresh-logical-name-with-$s-suffix-aux (name type names-to-avoid wrld counter) (declare (xargs :guard (and (symbolp name) (member-eq type '(function macro const stobj constrained-function nil)) (symbol-listp names-to-avoid) (plist-worldp wrld) (natp counter)))) (let ((__function__ 'fresh-logical-name-with-$s-suffix-aux)) (declare (ignorable __function__)) (b* (((when (zp counter)) (raise "Internal error: exhausted counter at ~x0." name) (mv name names-to-avoid)) (msg/nil (fresh-namep-msg-weak name type wrld)) ((when (or msg/nil (member-eq name names-to-avoid))) (fresh-logical-name-with-$s-suffix-aux (if type (add-suffix-to-fn-or-const name "$") (add-suffix name "$")) type names-to-avoid wrld (1- counter)))) (mv name (cons name names-to-avoid)))))
Theorem:
(defthm symbolp-of-fresh-logical-name-with-$s-suffix-aux.fresh-name (implies (symbolp name) (b* (((mv ?fresh-name ?updated-names-to-avoid) (fresh-logical-name-with-$s-suffix-aux name type names-to-avoid wrld counter))) (symbolp fresh-name))) :rule-classes :rewrite)
Theorem:
(defthm symbol-listp-of-fresh-logical-name-with-$s-suffix-aux.updated-names-to-avoid (implies (and (symbolp name) (symbol-listp names-to-avoid)) (b* (((mv ?fresh-name ?updated-names-to-avoid) (fresh-logical-name-with-$s-suffix-aux name type names-to-avoid wrld counter))) (symbol-listp updated-names-to-avoid))) :rule-classes :rewrite)
Function:
(defun fresh-logical-name-with-$s-suffix (name type names-to-avoid wrld) (declare (xargs :guard (and (symbolp name) (member-eq type '(function macro const stobj constrained-function nil)) (symbol-listp names-to-avoid) (plist-worldp wrld)))) (let ((__function__ 'fresh-logical-name-with-$s-suffix)) (declare (ignorable __function__)) (fresh-logical-name-with-$s-suffix-aux name type names-to-avoid wrld 1000)))
Theorem:
(defthm symbolp-of-fresh-logical-name-with-$s-suffix.fresh-name (implies (symbolp name) (b* (((mv ?fresh-name ?updated-names-to-avoid) (fresh-logical-name-with-$s-suffix name type names-to-avoid wrld))) (symbolp fresh-name))) :rule-classes :rewrite)
Theorem:
(defthm symbol-listp-of-fresh-logical-name-with-$s-suffix.updated-names-to-avoid (implies (and (symbolp name) (symbol-listp names-to-avoid)) (b* (((mv ?fresh-name ?updated-names-to-avoid) (fresh-logical-name-with-$s-suffix name type names-to-avoid wrld))) (symbol-listp updated-names-to-avoid))) :rule-classes :rewrite)