Lift a PFCS variable name to an ACL2 symbol.
The PFCS abstract syntax uses strings for variable names. These are turned into symbols in the shallowly embedded semantics. Here we define the mapping.
Assuming that PFCS variable names would normally consist of lowercase letters, digits, and underscores, we map lowercase letters to uppercase letters, digits to themselves, and underscores to dashes; we use the resulting string as name of the symbol, which we put in the current package. This way, idiomatic PFCS names are mapped to idiomatic ACL2 symbols.
This mapping is not bulletproof. The current package may import symbols from the Lisp package, for example, and a PFCS variable name may end up being mapped to a symbol in the Lisp package, which cannot be used as an ACL2 name. In the future, we may make this mapping more robust.
Function:
(defun lift-var-name-aux (chars) (declare (xargs :guard (character-listp chars))) (let ((__function__ 'lift-var-name-aux)) (declare (ignorable __function__)) (b* (((when (endp chars)) nil) (char (car chars)) (new-char (if (equal char #\_) #\- (str::upcase-char char))) (new-chars (lift-var-name-aux (cdr chars)))) (cons new-char new-chars))))
Theorem:
(defthm character-listp-of-lift-var-name-aux (b* ((new-chars (lift-var-name-aux chars))) (character-listp new-chars)) :rule-classes :rewrite)
Function:
(defun lift-var-name (name state) (declare (xargs :stobjs (state))) (declare (xargs :guard (namep name))) (let ((__function__ 'lift-var-name)) (declare (ignorable __function__)) (b* (((unless (name-case name :simple)) (raise "Indexed name ~x0 not supported." (name-fix name))) (string (name-simple->string name)) (chars (acl2::explode string)) (new-chars (lift-var-name-aux chars)) (new-string (acl2::implode new-chars))) (intern$ new-string (current-package+ state)))))
Theorem:
(defthm symbolp-of-lift-var-name (b* ((sym (lift-var-name name state))) (symbolp sym)) :rule-classes :rewrite)