Filtering...

basis-a

basis-a
other
(in-package "ACL2")
other
(defun-inline +f!-fn2
  (x y)
  (declare (type (unsigned-byte 60) x y))
  (the-fixnat (min (the (unsigned-byte 61) (+ x y)) (fixnum-bound))))
other
(defun-inline +f!-fn3
  (x y z)
  (declare (type (unsigned-byte 60) x y z))
  (the-fixnat (min (the (unsigned-byte 62) (+ x y z)) (fixnum-bound))))
+f!macro
(defmacro +f!
  (x y &optional z)
  (if z
    `(+f!-fn3 ,X ,Y ,Z)
    `(+f!-fn2 ,X ,Y)))
equal-x-constantfunction
(defun equal-x-constant
  (x const)
  (declare (xargs :guard (and (consp const)
        (eq (car const) 'quote)
        (consp (cdr const)))))
  (let ((guts (cadr const)))
    (cond ((symbolp guts) (list 'eq x const))
      ((or (acl2-numberp guts) (characterp guts)) (list 'eql x guts))
      ((stringp guts) (list 'equal x guts))
      (t (list 'equal x const)))))
match-tests-and-bindingsfunction
(defun match-tests-and-bindings
  (x pat tests bindings dups)
  (declare (xargs :guard (and (symbol-doublet-listp bindings) (true-listp dups))))
  (cond ((symbolp pat) (cond ((or (eq pat t) (eq pat nil) (keywordp pat)) (mv (cons (list 'eq x pat) tests) bindings dups))
        ((let ((len (length (symbol-name pat))))
           (and (> len 0)
             (eql #\* (char (symbol-name pat) 0))
             (eql #\* (char (symbol-name pat) (1- len))))) (mv (cons (list 'equal x pat) tests) bindings dups))
        ((and (> (length (symbol-name pat)) 0)
           (eql #\! (char (symbol-name pat) 0))) (mv (cons (list 'equal
                x
                (intern-in-package-of-symbol (subseq (symbol-name pat) 1 (length (symbol-name pat)))
                  pat))
              tests)
            bindings
            dups))
        ((eq pat '&) (mv tests bindings dups))
        (t (let ((binding (assoc-eq pat bindings)))
            (cond ((null binding) (mv tests (cons (list pat x) bindings) dups))
              (t (mv (cons (list 'equal x (cadr binding)) tests)
                  bindings
                  (add-to-set-eq pat dups))))))))
    ((atom pat) (mv (cons (equal-x-constant x (list 'quote pat)) tests)
        bindings
        dups))
    ((and (eq (car pat) 'quote)
       (consp (cdr pat))
       (null (cddr pat))) (mv (cons (equal-x-constant x pat) tests) bindings dups))
    ((and (eq (car pat) 'quote~)
       (consp (cdr pat))
       (symbolp (cadr pat))
       (null (cddr pat))) (mv (cons (list 'symbol-name-equal x (symbol-name (cadr pat)))
          tests)
        bindings
        dups))
    (t (mv-let (tests1 bindings1 dups1)
        (match-tests-and-bindings (list 'car x)
          (car pat)
          (cons (list 'consp x) tests)
          bindings
          dups)
        (match-tests-and-bindings (list 'cdr x)
          (cdr pat)
          tests1
          bindings1
          dups1)))))
match-clausefunction
(defun match-clause
  (x pat forms)
  (declare (xargs :guard t))
  (mv-let (tests bindings dups)
    (match-tests-and-bindings x pat nil nil nil)
    (list (if (null tests)
        t
        (cons 'and (reverse tests)))
      `(let ,(REVERSE BINDINGS)
        ,@(AND DUPS `((DECLARE (IGNORABLE ,@DUPS))))
        ,@FORMS))))
match-clause-listfunction
(defun match-clause-list
  (x clauses)
  (declare (xargs :guard (alistp clauses)))
  (cond ((consp clauses) (if (eq (caar clauses) '&)
        (list (match-clause x (caar clauses) (cdar clauses)))
        (cons (match-clause x (caar clauses) (cdar clauses))
          (match-clause-list x (cdr clauses)))))
    (t '((t nil)))))
case-matchmacro
(defmacro case-match
  (&rest args)
  (declare (xargs :guard (and (consp args)
        (symbolp (car args))
        (alistp (cdr args))
        (null (cdr (member-equal (assoc-eq '& (cdr args)) (cdr args)))))))
  (cons 'cond (match-clause-list (car args) (cdr args))))
wormhole-statuspfunction
(defun wormhole-statusp
  (whs)
  (declare (xargs :mode :logic :guard t))
  (or (equal whs nil)
    (and (consp whs)
      (or (eq (car whs) :enter) (eq (car whs) :skip)))))
wormhole-entry-codefunction
(defun wormhole-entry-code
  (whs)
  (declare (xargs :mode :logic :guard t))
  (if (and (consp whs) (eq (car whs) :skip))
    :skip :enter))
wormhole-datafunction
(defun wormhole-data
  (whs)
  (declare (xargs :mode :logic :guard t))
  (if (consp whs)
    (cdr whs)
    nil))
set-wormhole-entry-codefunction
(defun set-wormhole-entry-code
  (whs code)
  (declare (xargs :mode :logic :guard (or (eq code :enter) (eq code :skip))))
  (if (consp whs)
    (if (eq (car whs) code)
      whs
      (cons code (cdr whs)))
    (if (eq code :enter)
      whs
      (cons :skip whs))))
set-wormhole-datafunction
(defun set-wormhole-data
  (whs data)
  (declare (xargs :mode :logic :guard t))
  (if (consp whs)
    (if (equal (cdr whs) data)
      whs
      (cons (car whs) data))
    (cons :enter data)))
make-wormhole-statusfunction
(defun make-wormhole-status
  (old-status new-code new-data)
  (declare (xargs :mode :logic :guard (or (eq new-code :enter) (eq new-code :skip))))
  (if (consp old-status)
    (if (and (eq new-code (car old-status))
        (equal new-data (cdr old-status)))
      old-status
      (cons new-code new-data))
    (cons new-code new-data)))
tree-occur-eqfunction
(defun tree-occur-eq
  (x y)
  (declare (xargs :guard (symbolp x)))
  (cond ((consp y) (or (tree-occur-eq x (car y)) (tree-occur-eq x (cdr y))))
    (t (eq x y))))
wormhole-evalfunction
(defun wormhole-eval
  (qname qlambda free-vars)
  (declare (xargs :mode :logic :guard t)
    (ignore qname qlambda free-vars))
  nil)
other
(deflock *wormhole-lock*)
wormhole-eval-early-null-exit-pfunction
(defun wormhole-eval-early-null-exit-p
  (qlambda)
  (case-match qlambda
    (('quote ('lambda (whs)
         ('let ((info ('wormhole-data whs)))
           ('cond (('null info) whs) . &)))) (declare (ignore info whs))
      t)
    (& nil)))
sync-ephemeral-whs-with-persistent-whsfunction
(defun sync-ephemeral-whs-with-persistent-whs
  (name state)
  (declare (xargs :stobjs state))
  (if (and name (equal (f-get-global 'wormhole-name state) name))
    (mv-let (erp val state)
      (read-acl2-oracle state)
      (declare (ignore erp))
      (f-put-global 'wormhole-status val state))
    state))
set-persistent-whs-and-ephemeral-whsfunction
(defun set-persistent-whs-and-ephemeral-whs
  (name new-status state)
  (declare (xargs :stobjs state))
  (prog2$ (wormhole-eval name '(lambda nil new-status) new-status)
    (sync-ephemeral-whs-with-persistent-whs name state)))
wormholemacro
(defmacro wormhole
  (name entry-lambda
    input
    form
    &key
    (current-package 'same current-packagep)
    (useless-runes 'same useless-runesp)
    (ld-skip-proofsp 'same ld-skip-proofspp)
    (ld-redefinition-action 'save ld-redefinition-actionp)
    (ld-prompt ''wormhole-prompt)
    (ld-missing-input-ok 'same ld-missing-input-okp)
    (ld-always-skip-top-level-locals 'same
      ld-always-skip-top-level-localsp)
    (ld-pre-eval-filter 'same ld-pre-eval-filterp)
    (ld-pre-eval-print 'same ld-pre-eval-printp)
    (ld-post-eval-print 'same ld-post-eval-printp)
    (ld-evisc-tuple 'same ld-evisc-tuplep)
    (ld-error-triples 'same ld-error-triplesp)
    (ld-error-action 'same ld-error-actionp)
    (ld-query-control-alist 'same ld-query-control-alistp)
    (ld-verbose 'same ld-verbosep)
    (ld-user-stobjs-modified-warning ':same))
  `(with-wormhole-lock (prog2$ (wormhole-eval ,NAME ,ENTRY-LAMBDA :no-wormhole-lock)
      (wormhole1 ,NAME
        ,INPUT
        ,FORM
        (list ,@(APPEND
   (IF CURRENT-PACKAGEP
       (LIST `(CONS 'CURRENT-PACKAGE ,CURRENT-PACKAGE))
       NIL)
   (IF USELESS-RUNESP
       (LIST `(CONS 'USELESS-RUNES ,USELESS-RUNES))
       NIL)
   (IF LD-SKIP-PROOFSPP
       (LIST `(CONS 'LD-SKIP-PROOFSP ,LD-SKIP-PROOFSP))
       NIL)
   (IF LD-REDEFINITION-ACTIONP
       (LIST `(CONS 'LD-REDEFINITION-ACTION ,LD-REDEFINITION-ACTION))
       NIL)
   (LIST `(CONS 'LD-PROMPT ,LD-PROMPT))
   (IF LD-MISSING-INPUT-OKP
       (LIST `(CONS 'LD-MISSING-INPUT-OK ,LD-MISSING-INPUT-OK))
       NIL)
   (IF LD-ALWAYS-SKIP-TOP-LEVEL-LOCALSP
       (LIST
        `(CONS 'LD-ALWAYS-SKIP-TOP-LEVEL-LOCALS
               ,LD-ALWAYS-SKIP-TOP-LEVEL-LOCALS))
       NIL)
   (IF LD-PRE-EVAL-FILTERP
       (LIST `(CONS 'LD-PRE-EVAL-FILTER ,LD-PRE-EVAL-FILTER))
       NIL)
   (IF LD-PRE-EVAL-PRINTP
       (LIST `(CONS 'LD-PRE-EVAL-PRINT ,LD-PRE-EVAL-PRINT))
       NIL)
   (IF LD-POST-EVAL-PRINTP
       (LIST `(CONS 'LD-POST-EVAL-PRINT ,LD-POST-EVAL-PRINT))
       NIL)
   (IF LD-EVISC-TUPLEP
       (LIST `(CONS 'LD-EVISC-TUPLE ,LD-EVISC-TUPLE))
       NIL)
   (IF LD-ERROR-TRIPLESP
       (LIST `(CONS 'LD-ERROR-TRIPLES ,LD-ERROR-TRIPLES))
       NIL)
   (IF LD-ERROR-ACTIONP
       (LIST `(CONS 'LD-ERROR-ACTION ,LD-ERROR-ACTION))
       NIL)
   (IF LD-QUERY-CONTROL-ALISTP
       (LIST `(CONS 'LD-QUERY-CONTROL-ALIST ,LD-QUERY-CONTROL-ALIST))
       NIL)
   (IF LD-VERBOSEP
       (LIST `(CONS 'LD-VERBOSE ,LD-VERBOSE))
       NIL)
   (IF (EQ LD-USER-STOBJS-MODIFIED-WARNING :SAME)
       (LIST
        `(CONS 'LD-USER-STOBJS-MODIFIED-WARNING
               ,LD-USER-STOBJS-MODIFIED-WARNING))
       NIL)))))))
lambda-keywordpfunction
(defun lambda-keywordp
  (x)
  (and (symbolp x) (eql 1 (string<= "&" (symbol-name x)))))
arglistp1function
(defun arglistp1
  (lst)
  (cond ((atom lst) (null lst))
    (t (and (legal-variablep (car lst)) (arglistp1 (cdr lst))))))
arglistpfunction
(defun arglistp
  (lst)
  (and (arglistp1 lst) (no-duplicatesp-eq lst)))
find-first-bad-argfunction
(defun find-first-bad-arg
  (args)
  (declare (xargs :guard (and (true-listp args) (not (arglistp args)))))
  (cond ((not (symbolp (car args))) (mv (car args) "is not a symbol"))
    ((legal-constantp1 (car args)) (mv (car args) "has the syntax of a constant"))
    ((lambda-keywordp (car args)) (mv (car args) "is a lambda keyword"))
    ((keywordp (car args)) (mv (car args) "is in the KEYWORD package"))
    ((member-eq (car args) *common-lisp-specials-and-constants*) (mv (car args)
        "belongs to the list *common-lisp-specials-and-constants* ~
                    of symbols from the main Lisp package"))
    ((member-eq (car args) (cdr args)) (mv (car args) "occurs more than once in the list"))
    ((and (equal (symbol-package-name (car args))
         *main-lisp-package-name*)
       (not (member-eq (car args)
           *common-lisp-symbols-from-main-lisp-package*))) (mv (car args)
        "belongs to the main Lisp package but not to the list ~
                    *common-lisp-symbols-from-main-lisp-package*"))
    (t (find-first-bad-arg (cdr args)))))
process-defabbrev-declaresfunction
(defun process-defabbrev-declares
  (decls)
  (cond ((endp decls) nil)
    ((not (and (consp (car decls))
         (eq (caar decls) 'declare)
         (true-list-listp (cdar decls))
         (subsetp-eq (strip-cars (cdar decls))
           '(ignore ignorable type)))) (er hard
        'process-defabbrev-declares
        "In a DEFABBREV form, each expression after the argument list ~
              but before the body must be of the form (DECLARE decl1 .. ~
              declk), where each dcli is of the form (IGNORE ..), (IGNORABLE ~
              ..), or (TYPE ..).  The form ~x0 is thus illegal."
        (car decls)))
    (t (cons (kwote (car decls))
        (process-defabbrev-declares (cdr decls))))))
defabbrev1function
(defun defabbrev1
  (lst)
  (declare (xargs :guard (true-listp lst)))
  (cond ((null lst) nil)
    (t (cons (list 'list (list 'quote (car lst)) (car lst))
        (defabbrev1 (cdr lst))))))
defabbrevmacro
(defmacro defabbrev
  (fn args &rest body)
  (cond ((null body) (er hard
        (cons 'defabbrev fn)
        "The body of this DEFABBREV form is missing."))
    ((not (true-listp args)) (er hard
        (cons 'defabbrev fn)
        "The formal parameter list for a DEFABBREV must be a true list.  ~
              The argument list ~x0 is thus illegal."
        args))
    ((not (arglistp args)) (mv-let (culprit explan)
        (find-first-bad-arg args)
        (er hard
          (cons 'defabbrev fn)
          "The formal parameter list for a DEFABBREV must be a ~
                      list of distinct variables, but ~x0 does not meet these ~
                      conditions.  The element ~x1 ~@2."
          args
          culprit
          explan)))
    (t (mv-let (doc-string-list body)
        (if (and (stringp (car body)) (cdr body))
          (mv (list (car body)) (cdr body))
          (mv nil body))
        (cond ((null body) (er hard
              (cons 'defabbrev fn)
              "This DEFABBREV form has a doc string but no ~
                             body."))
          ((and (consp (car (last body)))
             (eq (caar (last body)) 'declare)) (er hard
              (cons 'defabbrev fn)
              "The body of this DEFABBREV form is a DECLARE ~
                             form, namely ~x0.  This is illegal and probably ~
                             is not what was intended."
              (car (last body))))
          (t `(defmacro ,FN
              ,ARGS
              ,@DOC-STRING-LIST
              (list 'let
                (list ,@(DEFABBREV1 ARGS))
                ,@(PROCESS-DEFABBREV-DECLARES (BUTLAST BODY 1))
                ',(CAR (LAST BODY))))))))))
*evisceration-mark*constant
(defconst *evisceration-mark* :evisceration-mark)
*evisceration-hash-mark*constant
(defconst *evisceration-hash-mark*
  (cons *evisceration-mark* "#"))
*evisceration-ellipsis-mark*constant
(defconst *evisceration-ellipsis-mark*
  (cons *evisceration-mark* "..."))
*evisceration-world-mark*constant
(defconst *evisceration-world-mark*
  (cons *evisceration-mark* "<world>"))
*evisceration-state-mark*constant
(defconst *evisceration-state-mark*
  (cons *evisceration-mark* "<state>"))
*evisceration-error-triple-marks*constant
(defconst *evisceration-error-triple-marks*
  (list nil nil *evisceration-state-mark*))
*evisceration-error-triple-df-marks*constant
(defconst *evisceration-error-triple-df-marks*
  (list nil :df *evisceration-state-mark*))
*evisceration-hiding-mark*constant
(defconst *evisceration-hiding-mark*
  (cons *evisceration-mark* "<hidden>"))
*anti-evisceration-mark*constant
(defconst *anti-evisceration-mark*
  (cons *evisceration-mark* ":EVISCERATION-MARK"))
evisceratedpmacro
(defmacro evisceratedp
  (eviscp x)
  `(and ,EVISCP (eq (car ,X) *evisceration-mark*)))
*sharp-atsign-ar*constant
(defconst *sharp-atsign-ar*
  (let ((dim (1+ *iprint-hard-bound-default*)))
    (compress1 'sharp-atsign-ar
      (cons `(:header :dimensions (,DIM)
          :maximum-length ,(1+ DIM)
          :name sharp-atsign-ar)
        (sharp-atsign-alist *iprint-hard-bound-default* nil)))))
get-sharp-atsignfunction
(defun get-sharp-atsign
  (i)
  (declare (xargs :guard (posp i)))
  (cond ((<= i *iprint-hard-bound-default*) (aref1 'sharp-atsign-ar *sharp-atsign-ar* i))
    (t (make-sharp-atsign i))))
iprint-alistp1function
(defun iprint-alistp1
  (x)
  (declare (xargs :guard t))
  (cond ((atom x) (null x))
    ((atom (cdr x)) (and (consp (car x)) (posp (caar x)) (null (cdr x))))
    (t (and (consp (car x))
        (posp (caar x))
        (consp (car (cdr x)))
        (integerp (caar (cdr x)))
        (< (caar (cdr x)) (caar x))
        (iprint-alistp1 (cdr x))))))
iprint-alistpfunction
(defun iprint-alistp
  (x)
  (declare (xargs :guard t))
  (or (eq x t) (natp x) (iprint-alistp1 x)))
update-iprint-alist-falfunction
(defun update-iprint-alist-fal
  (iprint-alist iprint-fal-new iprint-fal-old val)
  (declare (xargs :guard (and (iprint-alistp iprint-alist)
        (not (symbolp iprint-alist)))))
  (let ((pair (and iprint-fal-old
         (or (hons-get val iprint-fal-new)
           (hons-get val iprint-fal-old)))))
    (cond (pair (mv (cdr pair) iprint-alist iprint-fal-new))
      ((consp iprint-alist) (let ((index (1+ (caar iprint-alist))))
          (mv index
            (acons index val iprint-alist)
            (and iprint-fal-old (hons-acons val index iprint-fal-new)))))
      (t (let ((index (1+ iprint-alist)))
          (mv index
            (acons index val nil)
            (and iprint-fal-old (hons-acons val index iprint-fal-new))))))))
eviscerate1mutual-recursion
(mutual-recursion (defun eviscerate1
    (x v
      max-v
      max-n
      alist
      evisc-table
      hiding-cars
      iprint-alist
      iprint-fal-new
      iprint-fal-old
      eager-p)
    (declare (xargs :guard (and (integerp v)
          (integerp max-v)
          (integerp max-n)
          (alistp alist)
          (symbol-listp hiding-cars)
          (iprint-alistp iprint-alist)
          (iprint-falp iprint-fal-new)
          (iprint-falp iprint-fal-old))
        :measure (1+ (* 2 (acl2-count x)))))
    (let* ((temp (or (hons-assoc-equal x alist)
           (hons-assoc-equal x evisc-table))) (eager-pair (and eager-p
            (null (cdr temp))
            (consp x)
            (assert$? iprint-fal-old
              (or (hons-get x iprint-fal-new) (hons-get x iprint-fal-old))))))
      (cond ((cdr temp) (mv (cond ((stringp (cdr temp)) (cons *evisceration-mark* (cdr temp)))
              (t (cdr temp)))
            iprint-alist
            iprint-fal-new))
        ((atom x) (mv (cond ((eq x *evisceration-mark*) *anti-evisceration-mark*)
              (t x))
            iprint-alist
            iprint-fal-new))
        (eager-pair (mv (cons *evisceration-mark*
              (get-sharp-atsign (cdr eager-pair)))
            iprint-alist
            iprint-fal-new))
        ((= v max-v) (cond ((symbolp iprint-alist) (mv *evisceration-hash-mark* t iprint-fal-new))
            (t (mv-let (index iprint-alist iprint-fal-new)
                (update-iprint-alist-fal iprint-alist
                  iprint-fal-new
                  iprint-fal-old
                  x)
                (mv (cons *evisceration-mark* (get-sharp-atsign index))
                  iprint-alist
                  iprint-fal-new)))))
        ((member-eq (car x) hiding-cars) (mv *evisceration-hiding-mark* iprint-alist iprint-fal-new))
        (t (eviscerate1-lst x
            (1+ v)
            0
            max-v
            max-n
            alist
            evisc-table
            hiding-cars
            iprint-alist
            iprint-fal-new
            iprint-fal-old
            eager-p)))))
  (defun eviscerate1-lst
    (lst v
      n
      max-v
      max-n
      alist
      evisc-table
      hiding-cars
      iprint-alist
      iprint-fal-new
      iprint-fal-old
      eager-p)
    (declare (xargs :guard (and (integerp v)
          (natp n)
          (integerp max-v)
          (integerp max-n)
          (alistp alist)
          (symbol-listp hiding-cars)
          (iprint-alistp iprint-alist)
          (iprint-falp iprint-fal-new)
          (iprint-falp iprint-fal-old))
        :measure (* 2 (acl2-count lst))))
    (let* ((temp (or (hons-assoc-equal lst alist)
           (hons-assoc-equal lst evisc-table))) (eager-pair (and eager-p
            (null (cdr temp))
            (consp lst)
            (assert$? iprint-fal-old
              (or (hons-get lst iprint-fal-new)
                (hons-get lst iprint-fal-old))))))
      (cond ((cdr temp) (mv (cond ((stringp (cdr temp)) (cons *evisceration-mark* (cdr temp)))
              (t (cdr temp)))
            iprint-alist
            iprint-fal-new))
        ((atom lst) (mv (cond ((eq lst *evisceration-mark*) *anti-evisceration-mark*)
              (t lst))
            iprint-alist
            iprint-fal-new))
        (eager-pair (mv (cons *evisceration-mark*
              (get-sharp-atsign (cdr eager-pair)))
            iprint-alist
            iprint-fal-new))
        ((= n max-n) (cond ((symbolp iprint-alist) (mv (list *evisceration-ellipsis-mark*) t iprint-fal-new))
            (t (mv-let (index iprint-alist iprint-fal-new)
                (update-iprint-alist-fal iprint-alist
                  iprint-fal-new
                  iprint-fal-old
                  lst)
                (mv (cons *evisceration-mark* (get-sharp-atsign index))
                  iprint-alist
                  iprint-fal-new)))))
        (t (mv-let (first iprint-alist iprint-fal-new)
            (eviscerate1 (car lst)
              v
              max-v
              max-n
              alist
              evisc-table
              hiding-cars
              iprint-alist
              iprint-fal-new
              iprint-fal-old
              eager-p)
            (mv-let (rest iprint-alist iprint-fal-new)
              (eviscerate1-lst (cdr lst)
                v
                (1+ n)
                max-v
                max-n
                alist
                evisc-table
                hiding-cars
                iprint-alist
                iprint-fal-new
                iprint-fal-old
                eager-p)
              (mv (cons first rest) iprint-alist iprint-fal-new))))))))
eviscerate1pmutual-recursion
(mutual-recursion (defun eviscerate1p
    (x alist evisc-table hiding-cars)
    (declare (xargs :guard (symbol-listp hiding-cars)
        :measure (1+ (* 2 (acl2-count x)))))
    (let ((temp (or (hons-assoc-equal x alist)
           (hons-assoc-equal x evisc-table))))
      (cond ((cdr temp) t)
        ((atom x) (cond ((eq x *evisceration-mark*) t) (t nil)))
        ((member-eq (car x) hiding-cars) t)
        (t (eviscerate1p-lst x alist evisc-table hiding-cars)))))
  (defun eviscerate1p-lst
    (lst alist evisc-table hiding-cars)
    (declare (xargs :guard (symbol-listp hiding-cars)
        :measure (* 2 (acl2-count lst))))
    (let ((temp (or (hons-assoc-equal lst alist)
           (hons-assoc-equal lst evisc-table))))
      (cond ((cdr temp) t)
        ((atom lst) (cond ((eq lst *evisceration-mark*) t) (t nil)))
        (t (or (eviscerate1p (car lst) alist evisc-table hiding-cars)
            (eviscerate1p-lst (cdr lst) alist evisc-table hiding-cars)))))))
evisceratefunction
(defun eviscerate
  (x print-level
    print-length
    alist
    evisc-table
    hiding-cars
    iprint-alist
    iprint-fal-new
    iprint-fal-old
    eager-p)
  (declare (xargs :guard (and (or (null print-level) (integerp print-level))
        (or (null print-length) (integerp print-length))
        (alistp alist)
        (symbol-listp hiding-cars)
        (iprint-alistp iprint-alist)
        (iprint-falp iprint-fal-new)
        (iprint-falp iprint-fal-old))))
  (cond ((and (null print-level) (null print-length)) (cond ((eviscerate1p x alist evisc-table hiding-cars) (eviscerate1 x
            0
            -1
            -1
            alist
            evisc-table
            hiding-cars
            nil
            nil
            nil
            nil))
        (t (mv x iprint-alist iprint-fal-new))))
    (t (eviscerate1 (if eager-p
          (hons-copy x)
          x)
        0
        (or print-level -1)
        (or print-length -1)
        alist
        evisc-table
        hiding-cars
        iprint-alist
        iprint-fal-new
        iprint-fal-old
        eager-p))))
eviscerate-simplefunction
(defun eviscerate-simple
  (x print-level print-length alist evisc-table hiding-cars)
  (declare (xargs :guard (and (or (null print-level) (integerp print-level))
        (or (null print-length) (integerp print-length))
        (alistp alist)
        (symbol-listp hiding-cars))))
  (mv-let (result null-iprint-alist null-iprint-fal)
    (eviscerate x
      print-level
      print-length
      alist
      evisc-table
      hiding-cars
      nil
      nil
      nil
      nil)
    (declare (ignorable null-iprint-alist null-iprint-fal))
    (assert* (and (booleanp null-iprint-alist) (null null-iprint-fal))
      result)))
bounded-integer-listpfunction
(defun bounded-integer-listp
  (i j lst)
  (declare (xargs :guard (and (integerp i) (or (integerp j) (eq j 'infinity)))))
  (cond ((consp lst) (and (integerp (car lst))
        (<= i (car lst))
        (or (eq j 'infinity) (<= (car lst) j))
        (bounded-integer-listp i j (cdr lst))))
    (t (null lst))))
aset1-lstfunction
(defun aset1-lst
  (name alist ar)
  (declare (xargs :guard (eqlable-alistp alist)))
  (declare (xargs :guard (and (alistp alist)
        (array1p name ar)
        (bounded-integer-listp 0
          (- (car (dimensions name ar)) 1)
          (strip-cars alist)))))
  (cond ((endp alist) ar)
    (t (aset1-lst name
        (cdr alist)
        (aset1 name ar (caar alist) (cdar alist))))))
iprint-hard-boundfunction
(defun iprint-hard-bound
  (state)
  (f-get-global 'iprint-hard-bound state))
iprint-soft-boundfunction
(defun iprint-soft-bound
  (state)
  (f-get-global 'iprint-soft-bound state))
iprint-last-indexfunction
(defun iprint-last-index
  (state)
  (declare (xargs :guard (array1p 'iprint-ar (f-get-global 'iprint-ar state))))
  (iprint-last-index* (f-get-global 'iprint-ar state)))
iprint-ar-illegal-indexfunction
(defun iprint-ar-illegal-index
  (index state)
  (declare (xargs :guard (and (natp index)
        (array1p 'iprint-ar (f-get-global 'iprint-ar state))
        (natp (iprint-last-index state))
        (or (null (default 'iprint-ar (f-get-global 'iprint-ar state)))
          (integerp (default 'iprint-ar (f-get-global 'iprint-ar state)))))))
  (or (zp index)
    (let* ((iprint-ar (f-get-global 'iprint-ar state)) (bound (default 'iprint-ar iprint-ar)))
      (if (null bound)
        (> index (iprint-last-index* iprint-ar))
        (> index bound)))))
iprint-enabledpfunction
(defun iprint-enabledp
  (state)
  (declare (xargs :guard (array1p 'iprint-ar (f-get-global 'iprint-ar state))))
  (natp (aref1 'iprint-ar (f-get-global 'iprint-ar state) 0)))
iprint-blockedpfunction
(defun iprint-blockedp
  (state)
  (declare (xargs :guard (array1p 'iprint-ar (f-get-global 'iprint-ar state))))
  (let ((x (aref1 'iprint-ar (f-get-global 'iprint-ar state) 0)))
    (and (consp x) (cdr x))))
iprint-ar-aref1function
(defun iprint-ar-aref1
  (index state)
  (declare (xargs :guard (and (posp index)
        (array1p 'iprint-ar (f-get-global 'iprint-ar state))
        (< index
          (car (dimensions 'iprint-ar (f-get-global 'iprint-ar state)))))))
  (let ((iprint-ar (f-get-global 'iprint-ar state)))
    (aref1 'iprint-ar iprint-ar index)))
iprint-alistp1-weakfunction
(defun iprint-alistp1-weak
  (x)
  (declare (xargs :guard t))
  (cond ((atom x) (null x))
    (t (and (consp (car x))
        (posp (caar x))
        (iprint-alistp1-weak (cdr x))))))
collect-posp-indices-to-headerfunction
(defun collect-posp-indices-to-header
  (ar acc)
  (declare (xargs :guard (and (array1p 'iprint-ar ar) (iprint-alistp1-weak acc))))
  (cond ((endp ar) (er hard
        'collect-posp-indices-to-header
        "Implementation error: Failed to find :HEADER as expected!"))
    ((eq (caar ar) :header) acc)
    (t (collect-posp-indices-to-header (cdr ar)
        (if (eql (caar ar) 0)
          acc
          (cons (car ar) acc))))))
iprint-fal-namefunction
(defun iprint-fal-name
  (iprint-fal)
  (declare (xargs :guard (iprint-falp iprint-fal)))
  (if (consp iprint-fal)
    (cdr (last iprint-fal))
    iprint-fal))
iprint-eager-pfunction
(defun iprint-eager-p
  (iprint-fal)
  (declare (xargs :guard (iprint-falp iprint-fal)))
  (eq (iprint-fal-name iprint-fal) :eager))
init-iprint-falfunction
(defun init-iprint-fal
  (sym state)
  (declare (xargs :guard (and (symbolp sym)
        (iprint-falp (f-get-global 'iprint-fal state)))))
  (let* ((old-iprint-fal (f-get-global 'iprint-fal state)) (old-iprint-name (iprint-fal-name old-iprint-fal))
      (new-iprint-fal (cond ((null sym) nil)
          ((eq sym t) :iprint-fal)
          ((eq sym :same) old-iprint-name)
          (t sym))))
    (prog2$ (and (consp old-iprint-fal)
        (fast-alist-free old-iprint-fal))
      (pprogn (f-put-global 'iprint-fal new-iprint-fal state)
        (mv (cond ((eq old-iprint-name new-iprint-fal) nil)
            (new-iprint-fal (msg "Iprinting is enabled with~@0 sharing, with a ~
                                fast-alist whose name is ~x1."
                (if (iprint-eager-p new-iprint-fal)
                  " eager"
                  "")
                new-iprint-fal))
            (t (msg "Iprinting is enabled without sharing.")))
          state)))))
rollover-iprint-arfunction
(defun rollover-iprint-ar
  (iprint-alist last-index state)
  (declare (xargs :guard (and (iprint-alistp1 iprint-alist)
        (consp iprint-alist)
        (iprint-falp (f-get-global 'iprint-fal state))
        (array1p 'iprint-ar (f-get-global 'iprint-ar state))
        (posp last-index)
        (equal last-index (caar iprint-alist))
        (iprint-array-p (f-get-global 'iprint-ar state) last-index)
        (natp (f-get-global 'iprint-hard-bound state))
        (<= (* 4 (1+ (f-get-global 'iprint-hard-bound state)))
          (array-maximum-length-bound)))))
  (let* ((old-iprint-ar (f-get-global 'iprint-ar state)) (new-dim (1+ (max (iprint-hard-bound state) last-index)))
      (new-max-len (* 4 new-dim)))
    (cond ((< (array-maximum-length-bound) new-max-len) (prog2$ (er hard?
            'rollover-iprint-ar
            "Attempted to expand iprint-ar to a maximum-length of ~x0, ~
            exceeding (array-maximum-length-bound), which is ~x1."
            new-max-len
            (array-maximum-length-bound))
          state))
      (t (let* ((new-header `(:header :dimensions (,NEW-DIM)
               :maximum-length ,NEW-MAX-LEN
               :default ,LAST-INDEX
               :name iprint-ar
               :order :none)) (new-iprint-ar (compress1 'iprint-ar
                (cons new-header
                  (acons 0
                    0
                    (collect-posp-indices-to-header old-iprint-ar iprint-alist))))))
          (mv-let (msg state)
            (init-iprint-fal :same state)
            (declare (ignore msg))
            (f-put-global 'iprint-ar new-iprint-ar state)))))))
update-iprint-fal-recfunction
(defun update-iprint-fal-rec
  (iprint-fal-new iprint-fal-old)
  (declare (xargs :guard (iprint-falp iprint-fal-new)))
  (cond ((atom iprint-fal-new) iprint-fal-old)
    (t (update-iprint-fal-rec (cdr iprint-fal-new)
        (hons-acons (caar iprint-fal-new)
          (cdar iprint-fal-new)
          iprint-fal-old)))))
update-iprint-falfunction
(defun update-iprint-fal
  (iprint-fal-new state)
  (declare (xargs :guard (iprint-falp iprint-fal-new)))
  (cond ((atom iprint-fal-new) state)
    (t (f-put-global 'iprint-fal
        (update-iprint-fal-rec iprint-fal-new
          (f-get-global 'iprint-fal state))
        state))))
update-iprint-ar-falfunction
(defun update-iprint-ar-fal
  (iprint-alist iprint-fal-new iprint-fal-old state)
  (declare (xargs :guard (and (iprint-alistp1 iprint-alist)
        (consp iprint-alist)
        (equal iprint-fal-old (f-get-global 'iprint-fal state))
        (iprint-falp iprint-fal-old)
        (array1p 'iprint-ar (f-get-global 'iprint-ar state))
        (iprint-array-p (f-get-global 'iprint-ar state)
          (caar iprint-alist))
        (natp (f-get-global 'iprint-hard-bound state))
        (< (f-get-global 'iprint-hard-bound state)
          (car (dimensions 'iprint-ar (f-get-global 'iprint-ar state))))
        (<= (* 4 (1+ (f-get-global 'iprint-hard-bound state)))
          (array-maximum-length-bound))
        (iprint-falp iprint-fal-new))))
  (let ((last-index (caar iprint-alist)))
    (cond ((> last-index (iprint-hard-bound state)) (rollover-iprint-ar iprint-alist last-index state))
      (t (assert$ (or (null iprint-fal-old)
            (equal (f-get-global 'iprint-fal state) iprint-fal-old))
          (pprogn (update-iprint-fal iprint-fal-new state)
            (f-put-global 'iprint-ar
              (aset1-lst 'iprint-ar
                (acons 0 last-index iprint-alist)
                (f-get-global 'iprint-ar state))
              state)))))))
brr-evisc-tuple-oracle-update@parfunction
(defun brr-evisc-tuple-oracle-update@par nil nil)
iprint-oracle-updates@parfunction
(defun iprint-oracle-updates@par nil nil)
iprint-oracle-updates?function
(defun iprint-oracle-updates?
  (state)
  (declare (xargs :guard (array1p 'iprint-ar (f-get-global 'iprint-ar state))))
  (cond ((iprint-blockedp state) state)
    (t (iprint-oracle-updates state))))
eviscerate-top-state-pfunction
(defun eviscerate-top-state-p
  (state)
  (declare (xargs :stobjs state))
  (and (natp (f-get-global 'iprint-hard-bound state))
    (iprint-falp (f-get-global 'iprint-fal state))
    (array1p 'iprint-ar (f-get-global 'iprint-ar state))
    (consp (f-get-global 'iprint-ar state))
    (natp (iprint-last-index state))
    (iprint-array-p (f-get-global 'iprint-ar state)
      (1+ (iprint-last-index state)))
    (<= (* 4 (1+ (f-get-global 'iprint-hard-bound state)))
      (array-maximum-length-bound))
    (< (f-get-global 'iprint-hard-bound state)
      (car (dimensions 'iprint-ar (f-get-global 'iprint-ar state))))
    (= (maximum-length 'iprint-ar (f-get-global 'iprint-ar state))
      (* 4
        (car (dimensions 'iprint-ar (f-get-global 'iprint-ar state)))))))
eviscerate-topfunction
(defun eviscerate-top
  (x print-level
    print-length
    alist
    evisc-table
    hiding-cars
    state)
  (declare (xargs :guard (and (or (null print-level) (integerp print-level))
        (or (null print-length) (integerp print-length))
        (alistp alist)
        (symbol-listp hiding-cars)
        (eviscerate-top-state-p state))))
  (pprogn (iprint-oracle-updates? state)
    (brr-evisc-tuple-oracle-update state)
    (let ((iprint-fal-old (f-get-global 'iprint-fal state)))
      (mv-let (result iprint-alist iprint-fal-new)
        (eviscerate x
          print-level
          print-length
          alist
          evisc-table
          hiding-cars
          (and (iprint-enabledp state) (iprint-last-index state))
          nil
          iprint-fal-old
          (iprint-eager-p iprint-fal-old))
        (fast-alist-free-on-exit iprint-fal-new
          (let ((state (cond ((eq iprint-alist t) (f-put-global 'evisc-hitp-without-iprint t state))
                 ((atom iprint-alist) state)
                 (t (update-iprint-ar-fal iprint-alist
                     iprint-fal-new
                     iprint-fal-old
                     state)))))
            (mv result state)))))))
mv-letcmacro
(defmacro mv-letc
  (vars form body)
  `(mv-let ,VARS
    ,FORM
    (declare (type (unsigned-byte 60) col))
    ,BODY))
er-hard-valmacro
(defmacro er-hard-val
  (val &rest args)
  `(prog2$ (er hard? ,@ARGS) ,VAL))
er-hard?-val?macro
(defmacro er-hard?-val?
  (val quiet &rest args)
  `(if ,QUIET
    ,VAL
    (er-hard-val ,VAL ,@ARGS)))
the-fixnum!macro
(defmacro the-fixnum!
  (n ctx)
  `(the-fixnum (let ((n ,N))
      (if (and (<= n ,(FIXNUM-BOUND)) (>= n ,(- (1+ (FIXNUM-BOUND)))))
        n
        (er-hard-val 0
          ,CTX
          "The object ~x0 is not a fixnum (precisely:  not a ~
                      ~x1)."
          n
          *fixnum-type*)))))
the-fixnat!macro
(defmacro the-fixnat!
  (n ctx)
  `(the-fixnum (let ((n ,N))
      (if (and (<= n ,(FIXNUM-BOUND)) (>= n 0))
        n
        (er-hard-val 0
          ,CTX
          "The object ~x0 is not a nonnagative fixnum (precisely:  ~
                      not a ~x1)."
          n
          *fixnat-type*)))))
the-unsigned-byte!macro
(defmacro the-unsigned-byte!
  (bits n ctx)
  `(the (unsigned-byte ,BITS)
    (let ((n ,N) (bits ,BITS))
      (if (unsigned-byte-p bits n)
        n
        (er-hard-val 0
          ,CTX
          "The object ~x0 is not an (unsigned-byte ~x1)."
          n
          bits)))))
the-string!macro
(defmacro the-string!
  (s ctx)
  `(if (stringp ,S)
    (the string ,S)
    (er-hard-val "" ,CTX "Not a string:  ~x0." ,S)))
xxxjoin-fixnumfunction
(defun xxxjoin-fixnum
  (fn args root)
  (declare (xargs :guard (true-listp args)))
  (if (cdr args)
    (list 'the-fixnum
      (list fn
        (list 'the-fixnum (car args))
        (xxxjoin-fixnum fn (cdr args) root)))
    (if args
      (list 'the-fixnum (car args))
      root)))
+fmacro
(defmacro +f (&rest args) (xxxjoin-fixnum '+ args 0))
-fmacro
(defmacro -f
  (arg1 &optional arg2)
  (if arg2
    `(the-fixnum (- (the-fixnum ,ARG1) (the-fixnum ,ARG2)))
    `(the-fixnum (- (the-fixnum ,ARG1)))))
1-fmacro
(defmacro 1-f
  (x)
  (list 'the-fixnum (list '1- (list 'the-fixnum x))))
1+fmacro
(defmacro 1+f
  (x)
  (list 'the-fixnum (list '1+ (list 'the-fixnum x))))
charfmacro
(defmacro charf
  (s i)
  (list 'the 'character (list 'char s i)))
*fmacro
(defmacro *f (&rest args) (xxxjoin-fixnum '* args 1))
ppr-flat-right-marginmacro
(defmacro ppr-flat-right-margin
  nil
  '(f-get-global 'ppr-flat-right-margin state))
*ppr-special-syms*constant
(defconst *ppr-special-syms*
  '((case . 1) (case-match . 1)
    (defabsstobj . 1)
    (defaxiom . 1)
    (defchoose . 3)
    (defcong . 2)
    (defconst . 1)
    (defmacro . 2)
    (defstobj . 1)
    (defthm . 1)
    (defthmd . 1)
    (defun . 2)
    (defun-inline . 2)
    (defun-sk . 2)
    (defund . 2)
    (encapsulate . 1)
    (if . 2)
    (lambda . 1)
    (lambda$ . 1)
    (let . 1)
    (let* . 1)
    (mutual-recursion . 0)
    (mv-let . 2)
    (table . 1)))
other
(set-table-guard ppr-special-syms
  (and (symbolp key) (natp val)))
other
(table ppr-special-syms nil *ppr-special-syms* :clear)
symbol-to-fixnat-alistpfunction
(defun symbol-to-fixnat-alistp
  (x)
  (declare (xargs :guard t))
  (cond ((atom x) (eq x nil))
    (t (and (consp (car x))
        (symbolp (car (car x)))
        (fixnat-guard (cdr (car x)))
        (symbol-to-fixnat-alistp (cdr x))))))
special-term-numfunction
(defun special-term-num
  (sym state)
  (declare (xargs :guard (and (symbolp sym)
        (symbol-to-fixnat-alistp (table-alist 'ppr-special-syms (w state))))))
  (let ((pair (assoc-eq sym (table-alist 'ppr-special-syms (w state)))))
    (and pair (cdr pair))))
set-ppr-flat-right-marginfunction
(defun set-ppr-flat-right-margin
  (val state)
  (if (posp val)
    (f-put-global 'ppr-flat-right-margin val state)
    (prog2$ (illegal 'set-ppr-flat-right-margin
        "Set-ppr-flat-right-margin takes a positive integer ~
                      argument, unlike ~x0."
        (list (cons #\0 val)))
      state)))
ppr-tuple-pmutual-recursion
(mutual-recursion (defun ppr-tuple-p
    (x)
    (declare (xargs :guard t))
    (and (consp x)
      (consp (cdr x))
      (unsigned-byte-p 57 (cadr x))
      (case (car x)
        (flat t)
        (matched-keyword (and (consp (cddr x)) (keywordp (caddr x))))
        (dot t)
        '(ppr-tuple-p (cddr x))
        (keypair (and (consp (cddr x))
            (ppr-tuple-p (car (cddr x)))
            (ppr-tuple-p (cdr (cddr x)))))
        (wide (and (consp (cddr x)) (ppr-tuple-lst-p (cddr x))))
        (special-term (and (consp (cddr x))
            (consp (cdddr x))
            (consp (car (cdddr x)))
            (consp (cddddr x))
            (ppr-tuple-p (caddr x))
            (or (null (car (cadr (cddr x))))
              (unsigned-byte-p 57 (car (cadr (cddr x)))))
            (ppr-tuple-lst-p (cdr (cadr (cddr x))))
            (unsigned-byte-p 57 (car (cddr (cddr x))))
            (ppr-tuple-lst-p (cdr (cddr (cddr x))))))
        (otherwise (and (unsigned-byte-p 57 (car x))
            (consp (cddr x))
            (ppr-tuple-lst-p (cddr x)))))))
  (defun ppr-tuple-lst-p
    (lst)
    (declare (xargs :guard t))
    (cond ((atom lst) (null lst))
      (t (and (ppr-tuple-p (car lst)) (ppr-tuple-lst-p (cdr lst)))))))
keyword-param-valuepfunction
(defun keyword-param-valuep
  (tuple eviscp)
  (declare (type cons tuple)
    (xargs :guard (ppr-tuple-p tuple)))
  (or (and (eq (car tuple) 'flat)
      (not (or (atom (cddr tuple)) (evisceratedp eviscp (cddr tuple))))
      (null (cdr (cddr tuple))))
    (eq (car tuple) 'quote)
    (eq (car tuple) 'wide)
    (integerp (car tuple))))
cons-ppr1-guardpfunction
(defun cons-ppr1-guardp
  (x column width ppr-flat-right-margin)
  (declare (xargs :guard t))
  (and (ppr-tuple-p x)
    (ppr-tuple-lst-p column)
    (unsigned-byte-p 57 width)
    (unsigned-byte-p 57 ppr-flat-right-margin)
    (cond ((eq (car x) 'flat) (and (consp (cddr x)) (null (cdddr x))))
      (t t))
    (cond ((eq (car x) 'dot) (and (consp column)
          (consp (car column))
          (implies (eq (car (car column)) 'flat)
            (consp (cddr (car column))))))
      (t t))))
cons-ppr1function
(defun cons-ppr1
  (x column
    width
    ppr-flat-right-margin
    pair-keywords-p
    eviscp)
  (declare (type cons x)
    (type (unsigned-byte 57) width ppr-flat-right-margin)
    (xargs :guard (cons-ppr1-guardp x column width ppr-flat-right-margin)
      :split-types t))
  (cond ((and (eq (car x) 'flat)
       (or (atom (car (cddr x)))
         (evisceratedp eviscp (car (cddr x))))
       (consp column)) (let ((x1 (car (cddr x))) (row1 (car column)))
        (cond ((keywordp x1) (cond ((and (keyword-param-valuep row1 eviscp)
                 (or pair-keywords-p
                   (null (cdr column))
                   (eq (car (cadr column)) 'keypair)
                   (eq (car (cadr column)) 'matched-keyword))) (let ((n (+g! (cadr x) 1 (cadr row1))))
                  (declare (type (unsigned-byte 57) n))
                  (cond ((<= n width) (cons (cons 'keypair (cons n (cons x row1))) (cdr column)))
                    (t (cons (cons 'matched-keyword (cdr x)) column)))))
              ((eq (car row1) 'flat) (let ((n (+g! (cadr x) 1 (cadr row1))))
                  (declare (type (unsigned-byte 57) n))
                  (cond ((and (<= n ppr-flat-right-margin) (<= n width)) (cons (cons 'flat (cons n (cons x1 (cddr row1))))
                        (cdr column)))
                    (t (cons x column)))))
              (t (cons x column))))
          ((eq (car row1) 'flat) (let ((n (+g! (cadr x) 1 (cadr row1))))
              (declare (type (unsigned-byte 57) n))
              (cond ((and (<= n ppr-flat-right-margin) (<= n width)) (cons (cons 'flat (cons n (cons x1 (cddr row1))))
                    (cdr column)))
                (t (cons x column)))))
          (t (cons x column)))))
    ((and (eq (car x) 'dot) (consp column)) (let ((row1 (car column)))
        (cond ((eq (car row1) 'flat) (let ((n (+g! (cadr x) 1 (cadr row1))))
              (declare (type (unsigned-byte 57) n))
              (cond ((and (<= n ppr-flat-right-margin) (<= n width)) (cons (cons 'flat (cons n (car (cddr row1)))) (cdr column)))
                (t (cons x column)))))
          (t (cons x column)))))
    (t (cons x column))))
flsz-integerfunction
(defun flsz-integer
  (x print-base acc)
  (declare (type integer x)
    (type (unsigned-byte 5) print-base)
    (type (unsigned-byte 60) acc)
    (xargs :guard (print-base-p print-base)
      :ruler-extenders :lambdas :measure (cond ((not (and (integerp x)
             (natp acc)
             (< acc (fixnum-bound))
             (print-base-p print-base))) 0)
        ((< x 0) (+ 1 (- x)))
        ((< x print-base) 0)
        (t x))))
  (the-fixnat (cond ((not (mbt (and (integerp x) (natp acc) (print-base-p print-base)))) 0)
      ((mbe :logic (>= acc (fixnum-bound))
         :exec (= acc (fixnum-bound))) (fixnum-bound))
      ((< x 0) (flsz-integer (- x) print-base (1+f acc)))
      ((< x print-base) (1+f acc))
      (t (flsz-integer (truncate x print-base)
          print-base
          (1+f acc))))))
flsz-atomfunction
(defun flsz-atom
  (x print-base print-radix acc state)
  (declare (type (unsigned-byte 5) print-base)
    (type (unsigned-byte 60) acc)
    (xargs :guard (print-base-p print-base)
      :ruler-extenders :lambdas :measure (cond ((not (fixnat-guard acc)) 0) (t (acl2-count x)))))
  (the-fixnat (cond ((not (mbt (fixnat-guard acc))) 0)
      ((integerp x) (flsz-integer x
          print-base
          (cond ((null print-radix) acc)
            ((int= print-base 10) (+f! 1 acc))
            (t (+f! 2 acc)))))
      ((symbolp x) (the-fixnat (let* ((s (symbol-name x)) (len (min (fixnum-bound) (length s)))
              (s-sz (cond ((needs-slashes s state) (+f! 2 len)) (t len)))
              (acc (+f! acc s-sz)))
            (declare (type string s)
              (type (unsigned-byte 60) len s-sz acc))
            (the-fixnat (cond ((keywordp x) (+f! 1 acc))
                ((symbol-in-current-package-p x state) acc)
                (t (let* ((p (symbol-package-name x)) (p-len (min (fixnum-bound) (length p))))
                    (declare (type string p)
                      (type (unsigned-byte 60) p-len))
                    (cond ((needs-slashes p state) (+f! 4 acc p-len))
                      (t (+f! 2 acc p-len))))))))))
      ((rationalp x) (flsz-integer (numerator x)
          print-base
          (flsz-integer (denominator x)
            print-base
            (cond ((null print-radix) (+f! 1 acc))
              ((= print-base 10) (+f! 5 acc))
              (t (+f! 3 acc))))))
      ((complex-rationalp x) (flsz-atom (realpart x)
          print-base
          print-radix
          (mbe :logic (min (fixnum-bound)
              (max 0
                (flsz-atom (imagpart x) print-base print-radix acc state)))
            :exec (flsz-atom (imagpart x) print-base print-radix acc state))
          state))
      ((stringp x) (+f! 2 acc (min (fixnum-bound) (length x))))
      ((characterp x) (cond ((eql x #\
) (+f! 9 acc))
          ((eql x #\) (+f! 8 acc))
          ((eql x #\
) (+f! 8 acc))
          ((eql x #\ ) (+f! 7 acc))
          ((eql x #\) (+f! 6 acc))
          ((eql x #\	) (+f! 5 acc))
          (t (+f! 3 acc))))
      (t 0))))
*newline-string*constant
(defconst *newline-string* (string #\
))
flsz1function
(defun flsz1
  (x print-base print-radix j maximum state eviscp)
  (declare (type (unsigned-byte 5) print-base)
    (type (unsigned-byte 57) j maximum)
    (xargs :guard (print-base-p print-base)
      :measure (acl2-count x)
      :ruler-extenders :lambdas :verify-guards nil))
  (the-small t
    (cond ((> j maximum) j)
      ((atom x) (round-to-small t
          (flsz-atom x print-base print-radix j state)))
      ((evisceratedp eviscp x) (if (stringp (cdr x))
          (let ((p (search *newline-string* (cdr x) :from-end t)))
            (cond (p (+g! 1 maximum))
              (t (+g! j (min (length (cdr x)) *small-hi*)))))
          (+g! 1 maximum)))
      ((atom (cdr x)) (cond ((null (cdr x)) (flsz1 (car x)
              print-base
              print-radix
              (+g! 2 j)
              maximum
              state
              eviscp))
          (t (flsz1 (cdr x)
              print-base
              print-radix
              (flsz1 (car x)
                print-base
                print-radix
                (+g! 5 j)
                maximum
                state
                eviscp)
              maximum
              state
              eviscp))))
      ((and (eq (car x) 'quote) (consp (cdr x)) (null (cddr x))) (flsz1 (cadr x)
          print-base
          print-radix
          (+g! 1 j)
          maximum
          state
          eviscp))
      (t (flsz1 (cdr x)
          print-base
          print-radix
          (flsz1 (car x)
            print-base
            print-radix
            (+g! 1 j)
            maximum
            state
            eviscp)
          maximum
          state
          eviscp)))))
fmt-state-pfunction
(defun fmt-state-p
  (state)
  (declare (xargs :stobjs state))
  (and (state-p state)
    (small-nat-guard (f-get-global 'fmt-hard-right-margin state))
    (small-nat-guard (f-get-global 'fmt-soft-right-margin state))
    (alistp (table-alist 'evisc-table (w state)))
    (eviscerate-top-state-p state)
    (equal (array-order (header 'iprint-ar (f-get-global 'iprint-ar state)))
      nil)
    (small-nat-guard (ppr-flat-right-margin))
    (symbol-to-fixnat-alistp (table-alist 'ppr-special-syms (w state)))
    (not (assoc-eq 'quote (table-alist 'ppr-special-syms (w state))))))
flszfunction
(defun flsz
  (x j maximum state eviscp)
  (declare (type (unsigned-byte 60) j maximum)
    (xargs :guard (fmt-state-p state)))
  (flsz1 x
    (the-fixnat (print-base))
    (print-radix)
    (round-to-small t j)
    (round-to-small t maximum)
    state
    eviscp))
max-widthfunction
(defun max-width
  (lst maximum)
  (declare (type (signed-byte 58) maximum)
    (xargs :guard (ppr-tuple-lst-p lst)))
  (cond ((endp lst) maximum)
    ((> (cadr (car lst)) maximum) (max-width (cdr lst) (cadr (car lst))))
    (t (max-width (cdr lst) maximum))))
ppr1mutual-recursion
(mutual-recursion (defun ppr1
    (x print-base print-radix width rpc state eviscp)
    (declare (type (unsigned-byte 5) print-base)
      (type (unsigned-byte 57) width rpc)
      (xargs :guard (and (print-base-p print-base)
          (unsigned-byte-p 57 (ppr-flat-right-margin))
          (symbol-to-fixnat-alistp (table-alist 'ppr-special-syms (w state)))
          (not (assoc-eq 'quote (table-alist 'ppr-special-syms (w state)))))
        :measure (* 2 (acl2-count x))
        :ruler-extenders :lambdas :verify-guards nil))
    (if (mbt (symbol-to-fixnat-alistp (table-alist 'ppr-special-syms (w state))))
      (let ((sz (flsz1 x print-base print-radix rpc width state eviscp)) (width-1 (+g! width -1)))
        (declare (type (unsigned-byte 57) sz width-1))
        (cond ((or (atom x)
             (evisceratedp eviscp x)
             (and (<= sz width) (<= sz (ppr-flat-right-margin)))) (cons 'flat (cons sz (list x))))
          ((and (eq (car x) 'quote) (consp (cdr x)) (null (cddr x))) (let* ((x1 (ppr1 (cadr x)
                   print-base
                   print-radix
                   width-1
                   rpc
                   state
                   eviscp)))
              (cons 'quote (cons (+g! 1 (cadr x1)) x1))))
          (t (let* ((x1 (ppr1 (car x)
                   print-base
                   print-radix
                   width-1
                   (if (null (cdr x))
                     (+g! rpc 1)
                     0)
                   state
                   eviscp)) (hd-sz (cond ((or (atom (car x)) (evisceratedp eviscp (car x))) (cadr x1))
                    (t nil)))
                (special-term-num (if (symbolp (car x))
                    (special-term-num (car x) state)
                    nil))
                (special-term-num (and special-term-num
                    (true-listp (cdr x))
                    (>= (len (cdr x)) special-term-num)
                    special-term-num))
                (xc (ppr1-lst (cdr (if special-term-num
                        (nthcdr special-term-num x)
                        x))
                    print-base
                    print-radix
                    width-1
                    (+g! rpc 1)
                    special-term-num
                    state
                    eviscp))
                (x2 (cons x1 xc))
                (maximum (cond (hd-sz (max-width xc -1)) (t (max-width x2 0)))))
              (declare (type (signed-byte 58) maximum))
              (cond ((null hd-sz) (cons 1 (cons (+g! 1 maximum) x2)))
                (special-term-num (let* ((init-args (take special-term-num (cdr x))) (opt-name-pp (if (and init-args (symbolp (car init-args)))
                          (ppr1 (car init-args)
                            print-base
                            print-radix
                            (max (-f width hd-sz) 0)
                            0
                            state
                            eviscp)
                          nil))
                      (opt-name-pp (and opt-name-pp
                          (<= (+g! hd-sz 1 (cadr opt-name-pp)) width-1)
                          opt-name-pp))
                      (opt-name-sz (if opt-name-pp
                          (+g! 1 (cadr opt-name-pp))
                          0))
                      (x1 (if opt-name-pp
                          (cons 'flat
                            (cons (+g! hd-sz opt-name-sz)
                              (list (car x) (car init-args))))
                          x1))
                      (init-args-pp (and init-args
                          (ppr1-lst (if opt-name-pp
                              (cdr init-args)
                              init-args)
                            print-base
                            print-radix
                            width-1
                            (if (null xc)
                              (+g! rpc 1)
                              0)
                            nil
                            state
                            eviscp)))
                      (max-init-args-pp (max-width init-args-pp 0))
                      (init-args-indent (and init-args-pp
                          (>= (+g! hd-sz opt-name-sz max-init-args-pp) width-1)
                          (if (>= (+g! hd-sz max-init-args-pp) width-1)
                            (max 1 (-g! width-1 max-init-args-pp))
                            (+g! hd-sz 2))))
                      (xc-indent (if (or (>= maximum width-1) (equal init-args-indent 1))
                          1
                          2))
                      (maximum (max (max hd-sz (+g! maximum xc-indent -1))
                          (cond (init-args-indent (+g! init-args-indent -1 max-init-args-pp))
                            (t (+g! hd-sz opt-name-sz 1 max-init-args-pp))))))
                    (declare (type (unsigned-byte 57) maximum max-init-args-pp))
                    (cons 'special-term
                      (cons (+g! 1 maximum)
                        (cons x1
                          (cons (cons init-args-indent init-args-pp)
                            (cons xc-indent xc)))))))
                ((<= (+g! hd-sz 2 maximum) width) (cons 'wide (cons (+g! hd-sz 2 maximum) x2)))
                ((< maximum width) (cons (min 5 (-g! width maximum))
                    (cons (+g! maximum (min 5 (-g! width maximum))) x2)))
                (t (cons 1 (cons (+g! 1 maximum) x2))))))))
      nil))
  (defun ppr1-lst
    (lst print-base
      print-radix
      width
      rpc
      pair-keywords-p
      state
      eviscp)
    (declare (type (unsigned-byte 5) print-base)
      (type (unsigned-byte 57) width)
      (type (unsigned-byte 57) rpc)
      (xargs :guard (and (print-base-p print-base)
          (unsigned-byte-p 57 (ppr-flat-right-margin))
          (symbol-to-fixnat-alistp (table-alist 'ppr-special-syms (w state)))
          (not (assoc-eq 'quote (table-alist 'ppr-special-syms (w state)))))
        :measure (1+ (* 2 (acl2-count lst)))
        :ruler-extenders :lambdas :verify-guards nil))
    (cond ((atom lst) (cond ((null lst) nil)
          (t (cons-ppr1 '(dot 1)
              (list (ppr1 lst print-base print-radix width rpc state eviscp))
              width
              (ppr-flat-right-margin)
              nil
              eviscp))))
      ((evisceratedp eviscp lst) (cons-ppr1 '(dot 1)
          (list (ppr1 lst print-base print-radix width rpc state eviscp))
          width
          (ppr-flat-right-margin)
          nil
          eviscp))
      ((null (cdr lst)) (list (ppr1 (car lst)
            print-base
            print-radix
            width
            rpc
            state
            eviscp)))
      (t (cons-ppr1 (ppr1 (car lst) print-base print-radix width 0 state eviscp)
          (ppr1-lst (cdr lst)
            print-base
            print-radix
            width
            rpc
            pair-keywords-p
            state
            eviscp)
          width
          (ppr-flat-right-margin)
          pair-keywords-p
          eviscp)))))
newlinefunction
(defun newline
  (channel state)
  (declare (xargs :guard (and (symbolp channel)
        (open-output-channel-p channel :character state))))
  (princ$ #\
 channel state))
fmt-hard-right-marginfunction
(defun fmt-hard-right-margin
  (state)
  (declare (xargs :guard (small-nat-guard (f-get-global 'fmt-hard-right-margin state))))
  (the (unsigned-byte 57)
    (f-get-global 'fmt-hard-right-margin state)))
fmt-soft-right-marginfunction
(defun fmt-soft-right-margin
  (state)
  (declare (xargs :guard (small-nat-guard (f-get-global 'fmt-soft-right-margin state))))
  (the (unsigned-byte 57)
    (f-get-global 'fmt-soft-right-margin state)))
set-fmt-hard-right-marginfunction
(defun set-fmt-hard-right-margin
  (n state)
  (declare (xargs :guard t :stobjs state))
  (cond ((and (small-nat-guard n) (not (= n 0))) (f-put-global 'fmt-hard-right-margin n state))
    (t (prog2$ (er hard?
          'set-fmt-hard-right-margin
          "The fmt-hard-right-margin must be a positive integer no ~
                   greater than ~x0, but ~x1 is not."
          *small-hi*
          n)
        state))))
set-fmt-soft-right-marginfunction
(defun set-fmt-soft-right-margin
  (n state)
  (declare (xargs :guard t :stobjs state))
  (cond ((and (small-nat-guard n) (not (= n 0))) (f-put-global 'fmt-soft-right-margin n state))
    (t (prog2$ (er hard?
          'set-fmt-soft-right-margin
          "The fmt-soft-right-margin must be a positive integer no ~
                   greater than ~x0, but ~x1 is not."
          *small-hi*
          n)
        state))))
write-for-readfunction
(defun write-for-read
  (state)
  (declare (xargs :guard t))
  (f-get-global 'write-for-read state))
spaces1function
(defun spaces1
  (n col hard-right-margin channel state)
  (declare (type (unsigned-byte 60) n col)
    (type (unsigned-byte 57) hard-right-margin)
    (type symbol channel)
    (xargs :measure (nfix (+ (* 2 n) col))
      :guard (open-output-channel-p channel :character state)))
  (cond ((mbt (and (natp n) (natp col) (natp hard-right-margin))) (cond ((= n 0) state)
        ((> col hard-right-margin) (pprogn (if (write-for-read state)
              state
              (princ$ #\\ channel state))
            (newline channel state)
            (spaces1 n 0 hard-right-margin channel state)))
        (t (pprogn (princ$ #\  channel state)
            (spaces1 (the (unsigned-byte 60) (1- n))
              (the (unsigned-byte 60) (1+ col))
              hard-right-margin
              channel
              state)))))
    (t state)))
make-spaces-array-recfunction
(defun make-spaces-array-rec
  (n acc)
  (if (zp n)
    (cons (cons 0 "") acc)
    (make-spaces-array-rec (1- n)
      (cons (cons n (coerce (make-list n :initial-element #\ ) 'string))
        acc))))
make-spaces-arrayfunction
(defun make-spaces-array
  (n)
  (compress1 'acl2-built-in-spaces-array
    (cons `(:header :dimensions (,(1+ N))
        :maximum-length ,(+ 2 N)
        :default nil
        :name acl2-built-in-spaces-array)
      (make-spaces-array-rec n nil))))
*acl2-built-in-spaces-array*constant
(defconst *acl2-built-in-spaces-array*
  (make-spaces-array 200))
spacesfunction
(defun spaces
  (n col channel state)
  (declare (type (unsigned-byte 60) n col)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (open-output-channel-p channel :character state))))
  (let ((hard-right-margin (fmt-hard-right-margin state)) (result-col (+f! n col)))
    (declare (type (unsigned-byte 57) hard-right-margin)
      (type (unsigned-byte 60) result-col))
    (if (and (<= result-col hard-right-margin) (<= n 200))
      (princ$ (aref1 'acl2-built-in-spaces-array
          *acl2-built-in-spaces-array*
          n)
        channel
        state)
      (spaces1 n col hard-right-margin channel state))))
flpr1mutual-recursion
(mutual-recursion (defun flpr1
    (x channel state eviscp)
    (declare (type symbol channel)
      (xargs :guard (open-output-channel-p channel :character state)
        :verify-guards nil
        :measure (1+ (* 2 (acl2-count x)))))
    (cond ((atom x) (prin1$ x channel state))
      ((evisceratedp eviscp x) (princ$ (if (atom (cdr x))
            (cdr x)
            "<ILL-FORMED-EVISCERATED-OBJECT>")
          channel
          state))
      ((and (eq (car x) 'quote) (consp (cdr x)) (null (cddr x))) (pprogn (princ$ #\' channel state)
          (flpr1 (cadr x) channel state eviscp)))
      (t (pprogn (princ$ #\( channel state)
          (flpr11 x channel state eviscp)))))
  (defun flpr11
    (x channel state eviscp)
    (declare (type symbol channel)
      (xargs :guard (and (consp x)
          (open-output-channel-p channel :character state))
        :measure (* 2 (acl2-count x))))
    (if (mbt (consp x))
      (pprogn (flpr1 (car x) channel state eviscp)
        (cond ((null (cdr x)) (princ$ #\) channel state))
          ((or (atom (cdr x)) (evisceratedp eviscp (cdr x))) (pprogn (princ$ " . " channel state)
              (flpr1 (cdr x) channel state eviscp)
              (princ$ #\) channel state)))
          (t (pprogn (princ$ #\  channel state)
              (flpr11 (cdr x) channel state eviscp)))))
      state)))
flprfunction
(defun flpr
  (x channel state eviscp)
  (declare (type symbol channel)
    (xargs :guard (open-output-channel-p channel :character state)))
  (flpr1 x channel state eviscp))
ppr2-flatfunction
(defun ppr2-flat
  (x channel state eviscp)
  (declare (xargs :guard (and (symbolp channel)
        (open-output-channel-p channel :character state))))
  (cond ((null x) state)
    ((or (atom x) (evisceratedp eviscp x)) (pprogn (princ$ #\. channel state)
        (princ$ #\  channel state)
        (flpr1 x channel state eviscp)))
    (t (pprogn (flpr1 (car x) channel state eviscp)
        (cond ((cdr x) (pprogn (princ$ #\  channel state)
              (ppr2-flat (cdr x) channel state eviscp)))
          (t state))))))
ppr2-columnmutual-recursion
(mutual-recursion (defun ppr2-column
    (lst loc col channel state eviscp)
    (declare (type (unsigned-byte 57) loc col)
      (xargs :guard (and (ppr-tuple-lst-p lst)
          (fmt-state-p state)
          (symbolp channel)
          (open-output-channel-p channel :character state))
        :measure (acl2-count lst)
        :ruler-extenders :lambdas :verify-guards nil))
    (if (mbt (ppr-tuple-lst-p lst))
      (cond ((null lst) state)
        (t (pprogn (spaces (if (> col loc)
                (+g! col (- loc))
                1)
              loc
              channel
              state)
            (ppr2 (car lst)
              (if (> col loc)
                col
                (+g! loc 1))
              channel
              state
              eviscp)
            (cond ((null (cdr lst)) state)
              (t (pprogn (newline channel state)
                  (ppr2-column (cdr lst) 0 col channel state eviscp)))))))
      state))
  (defun ppr2
    (x col channel state eviscp)
    (declare (type (unsigned-byte 57) col)
      (xargs :guard (and (ppr-tuple-p x)
          (fmt-state-p state)
          (symbolp channel)
          (open-output-channel-p channel :character state))
        :measure (acl2-count x)
        :ruler-extenders :lambdas :verify-guards nil))
    (if (mbt (ppr-tuple-p x))
      (case (car x)
        (flat (ppr2-flat (cddr x) channel state eviscp))
        (matched-keyword (ppr2-flat (cddr x) channel state eviscp))
        (dot (princ$ #\. channel state))
        '(pprogn (princ$ #\' channel state)
          (ppr2 (cddr x) (+g! 1 col) channel state eviscp))
        (keypair (pprogn (ppr2-flat (cddr (car (cddr x))) channel state eviscp)
            (princ$ #\  channel state)
            (ppr2 (cdr (cddr x))
              (+g! col 1 (cadr (car (cddr x))))
              channel
              state
              eviscp)))
        (wide (pprogn (princ$ #\( channel state)
            (ppr2-flat (cddr (car (cddr x))) channel state eviscp)
            (ppr2-column (cdr (cddr x))
              (+g! col 1 (cadr (car (cddr x))))
              (+g! col 2 (cadr (car (cddr x))))
              channel
              state
              eviscp)
            (princ$ #\) channel state)))
        (special-term (let* ((rx (cddr x)) (x1 (car rx))
              (x1-sz (cadr x1))
              (init-args-pp-info (cadr rx))
              (init-args-indent (car init-args-pp-info))
              (init-args-pp (cdr init-args-pp-info))
              (init-args-pp-col (cond (init-args-indent (+g! col init-args-indent))
                  (t (+g! col x1-sz 2))))
              (x2-indent (car (cddr rx)))
              (x2 (cdr (cddr rx))))
            (pprogn (princ$ #\( channel state)
              (ppr2 x1 (+g! col 1) channel state eviscp)
              (if init-args-indent
                (newline channel state)
                state)
              (if init-args-pp
                (ppr2-column init-args-pp
                  (if init-args-indent
                    0
                    (+g! col x1-sz 1))
                  init-args-pp-col
                  channel
                  state
                  eviscp)
                state)
              (newline channel state)
              (ppr2-column x2 0 (+g! col x2-indent) channel state eviscp)
              (princ$ #\) channel state))))
        (otherwise (pprogn (princ$ #\( channel state)
            (ppr2 (car (cddr x)) (+g! col (car x)) channel state eviscp)
            (cond ((cdr (cddr x)) (pprogn (newline channel state)
                  (ppr2-column (cdr (cddr x))
                    0
                    (+g! col (car x))
                    channel
                    state
                    eviscp)
                  (princ$ #\) channel state)))
              (t (princ$ #\) channel state))))))
      state)))
*fmt-ppr-indentation*constant
(defconst *fmt-ppr-indentation* 0)
pprfunction
(defun ppr
  (x col channel state eviscp)
  (declare (type (unsigned-byte 57) col)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (open-output-channel-p channel :character state))))
  (let ((fmt-hard-right-margin (fmt-hard-right-margin state)))
    (declare (type (unsigned-byte 57) fmt-hard-right-margin))
    (cond ((< col fmt-hard-right-margin) (ppr2 (ppr1 x
            (print-base)
            (print-radix)
            (-g! fmt-hard-right-margin col)
            0
            state
            eviscp)
          col
          channel
          state
          eviscp))
      (t (let ((er (er hard?
               'ppr
               "The `col' argument to ppr must be less than value ~
                    of the state global variable ~
                    fmt-hard-right-margin, but ~x0 is not less than ~
                    ~x1."
               col
               fmt-hard-right-margin)))
          (declare (ignore er))
          state)))))
*illegal-fmt-keys*constant
(defconst *illegal-fmt-keys*
  '(bad-evisc-tuple bad-tilde-&v-arg
    bad-tilde-*-arg
    bad-tilde-@-arg
    bad-tilde-c-arg
    bad-tilde-n-arg
    bad-tilde-s-arg
    bad-tilde-t-arg-natp
    bad-tilde-t-arg-not-natp
    bad-tilde-_-arg
    find-alternative-skip
    find-alternative-start
    find-alternative-start1-a
    find-alternative-start1-b
    find-alternative-stop
    tilde-arg-points-past-string
    unbound-tilde-arg
    unrecognized-tilde-arg))
illegal-fmt-stringfunction
(defun illegal-fmt-string
  (key)
  (declare (xargs :guard (member-eq key *illegal-fmt-keys*)))
  (case key
    (bad-evisc-tuple "In the fmt string displayed below, the tilde directive at location ~x0 ~
      associates character ~x1 with ~x2, which does not satisfy ~x3.~|~%~x4")
    (bad-tilde-&v-arg "The tilde directive at location ~x0 in the fmt string below uses the ~
      variable ~x1.  That ~s2 directive requires a true list, but it was ~
      supplied the value ~x3.~|~%~x4")
    (bad-tilde-*-arg "The tilde directive, ~~*, at location ~x0 in the fmt string below uses ~
      the variable ~x1.  That directive requires a list of the form ("str0" ~
      "str1" "str2" "str3" lst . alist) such that lst is a true-list ~
      and alist satisfies ~x2, but it was supplied the value ~x3.~|~%~x4")
    (bad-tilde-@-arg "The tilde-@ directive at position ~x0 of the string below is illegal ~
      because its variable evaluated to ~x1, which does not satisfy ~
      ~x2.~|~%~x3")
    (bad-tilde-c-arg "The tilde-c directive at position ~x0 of the string below is illegal ~
      because its variable evaluated to ~x1, which is not of the form (n . ~
      width), where n and width are integers and width is nonnegative.~|~%~x2")
    (bad-tilde-n-arg "The tilde directive at location ~x0 in the fmt string below uses the ~
      variable ~x1.  That ~s2 directive requires either an integer or a CONS ~
      whose CAR is an integer, but it was supplied the value ~x3.~|~%~x4")
    (bad-tilde-s-arg "The tilde-~s0 directive at position ~x1 of the string below is illegal ~
      because its variable evaluated to ~x2, which is not a symbol, a string, ~
      or a number.~|~%~x3")
    (bad-tilde-t-arg-natp "It is illegal to tab past the value of (@ fmt-hard-right-margin), ~x0, ~
      and hence the directive ~~t~s1 to tab to column ~x2 is illegal.  See ~
      :DOC set-fmt-hard-right-margin.")
    (bad-tilde-t-arg-not-natp "The tilde directive at location ~x0 in the fmt string below uses the ~
      variable ~x1.  That ~~t directive requires a natural number, but it was ~
      supplied the value ~x2.~|~%~x3")
    (bad-tilde-_-arg "The tilde-_ directive at position ~x0 of the string below is illegal ~
      because its variable evaluated to ~x1, which fails to be a natural ~
      number not exceeding ~x2.~|~%~x3")
    (find-alternative-skip "While looking for the terminating bracket of a tilde alternative ~
      directive in the string below we ran off the end of the string.~|~%~x0")
    (find-alternative-start "The tilde-# directive at ~x0 in the fmt string below must be followed ~
      immediately by ~~[.~|~%~x1")
    (find-alternative-start1-a "The tilde-# directive ~s0 at position ~x1 of the string below ~
      does not have enough alternative clauses.  When the terminal bracket ~
      was reached we still needed ~#2~[~/1 more alternative~/~x3 more ~
      alternatives~].~|~%~x4")
    (find-alternative-start1-b "While searching for the appropriate alternative clause of a tilde-# ~
      directive in the string below, we ran off the end of the string.~|~%~x0")
    (find-alternative-stop "While looking for the end of a tilde-# directive's alternative clause ~
      in the string below, we ran off the end of the string.~|~%~x0")
    (tilde-arg-points-past-string "The tilde directive at location ~x0 in the fmt string below requires ~
      that we look at the character ~x1 further down in the string.  But the ~
      string terminates at location ~x2.~|~%~x3")
    (unbound-tilde-arg "Unbound Fmt Variable.  The tilde directive at location ~x0 in the fmt ~
      string below uses the variable ~x1.  But this variable is not bound in ~
      the association list, ~x2, supplied with the fmt string.~|~%~x3")
    (unrecognized-tilde-arg "The tilde directive at position ~x0 of the string below is ~
      unrecognized.~|~%~x1")
    (otherwise (er hard
        'illegal-fmt-string
        "Implementation error in illegal-fmt-string: unknown key, ~x0."
        key))))
illegal-fmt-msgmacro
(defmacro illegal-fmt-msg
  (key &rest args)
  (declare (xargs :guard (member-eq key *illegal-fmt-keys*)))
  `(msg "Illegal Fmt Syntax.  ~@0"
    (msg ,(ILLEGAL-FMT-STRING KEY) ,@ARGS)))
scan-past-whitespacefunction
(defun scan-past-whitespace
  (s i maximum)
  (declare (type (unsigned-byte 60) i maximum)
    (type string s)
    (xargs :guard (<= maximum (length s))
      :measure (nfix (- maximum i))
      :ruler-extenders :all))
  (the-fixnat (cond ((not (mbt (and (integerp i) (integerp maximum)))) maximum)
      ((< i maximum) (cond ((member (charf s i) '(#\  #\	 #\
)) (scan-past-whitespace s (+f i 1) maximum))
          (t i)))
      (t maximum))))
zero-one-or-morefunction
(defun zero-one-or-more
  (x)
  (declare (xargs :guard (or (integerp x) (true-listp x))))
  (let ((n (cond ((integerp x) x) (t (length x)))))
    (case n (0 0) (1 1) (otherwise 2))))
find-alternative-skipfunction
(defun find-alternative-skip
  (s i maximum quiet)
  (declare (type (unsigned-byte 60) i maximum)
    (type string s)
    (xargs :guard (and (<= maximum (length s)) (<= i maximum))
      :measure (nfix (- maximum i))
      :ruler-extenders :lambdas))
  (the-fixnat (cond ((and (mbt (and (integerp i) (integerp maximum)))
         (< i (1-f maximum))) (let ((char-s-i (charf s i)))
          (declare (type character char-s-i))
          (case char-s-i
            (#\~ (let ((i+2 (+f 2 i)) (char-s-1+i (charf s (1+f i))))
                (declare (type character char-s-1+i)
                  (type (unsigned-byte 60) i+2))
                (case char-s-1+i
                  (#\] i+2)
                  (#\[ (let ((new-i (find-alternative-skip s i+2 maximum quiet)))
                      (declare (type (unsigned-byte 60) new-i))
                      (cond ((and (not (= new-i 0))
                           (mbt (and (integerp new-i) (< i new-i)))) (find-alternative-skip s new-i maximum quiet))
                        (t 0))))
                  (otherwise (find-alternative-skip s i+2 maximum quiet)))))
            (otherwise (find-alternative-skip s (+f 1 i) maximum quiet)))))
      (t (er-hard?-val? 0
          quiet
          'find-alternative-skip
          "~@0"
          (illegal-fmt-msg find-alternative-skip s))))))
find-alternative-start1function
(defun find-alternative-start1
  (x s i maximum quiet)
  (declare (type (unsigned-byte 60) x i maximum)
    (type string s)
    (xargs :guard (and (<= maximum (length s)) (<= i maximum))
      :measure (nfix (- maximum i))
      :ruler-extenders :lambdas))
  (the-fixnat (cond ((= x 0) i)
      ((and (mbt (and (natp x) (integerp i) (integerp maximum)))
         (< i (1-f maximum))) (let ((char-s-i (charf s i)))
          (declare (type character char-s-i))
          (case char-s-i
            (#\~ (let ((char-s-1+-i (charf s (1+f i))))
                (declare (type character char-s-1+-i))
                (case char-s-1+-i
                  (#\/ (find-alternative-start1 (1-f x) s (+f 2 i) maximum quiet))
                  (#\] (er-hard?-val? 0
                      quiet
                      'find-alternative-start1
                      "~@0"
                      (illegal-fmt-msg find-alternative-start1-a
                        "terminating"
                        i
                        (zero-one-or-more x)
                        x
                        s)))
                  (#\[ (let ((k (find-alternative-skip s (+f 2 i) maximum quiet)))
                      (declare (type (unsigned-byte 60) k))
                      (cond ((= k 0) 0)
                        (t (find-alternative-start1 x s k maximum quiet)))))
                  (otherwise (find-alternative-start1 x s (+f 2 i) maximum quiet)))))
            (otherwise (find-alternative-start1 x s (+f 1 i) maximum quiet)))))
      (t (er-hard?-val? 0
          quiet
          'find-alternative-start1
          "~@0"
          (illegal-fmt-msg find-alternative-start1-b s))))))
fmt-charfunction
(defun fmt-char
  (s i j maximum err-flg)
  (declare (type (unsigned-byte 60) i maximum)
    (type (integer 1 4) j)
    (type string s)
    (xargs :guard (and (<= maximum (length s)) (< i maximum))))
  (the character
    (let ((index (+f! i j)))
      (declare (type (unsigned-byte 60) index))
      (cond ((< index maximum) (charf s index))
        (t (prog2$ (cond (err-flg (mv-let (i j)
                  (if (or (= 0 i)
                      (eql (charf s i) #\~)
                      (not (eql (charf s (1-f i)) #\~)))
                    (mv i j)
                    (mv (1-f i) (1+f j)))
                  (er hard?
                    'fmt-char
                    "~@0"
                    (illegal-fmt-msg tilde-arg-points-past-string i j maximum s))))
              (t nil))
            *null-char*))))))
find-alternative-startfunction
(defun find-alternative-start
  (x s i maximum quiet)
  (declare (type (unsigned-byte 60) i maximum)
    (type string s)
    (xargs :guard (<= maximum (length s))))
  (the-fixnat (cond ((not (< i (-f maximum 4))) (er-hard?-val? 0
          quiet
          'find-alternative-start
          "~@0"
          (illegal-fmt-msg tilde-arg-points-past-string i 4 maximum s)))
      (t (let ((x (cond ((natp x) (the-fixnat! x 'find-alternative-start))
               ((and (consp x) (atom (cdr x))) 0)
               (t 1))))
          (declare (type (unsigned-byte 60) x))
          (cond ((not (and (eql (the character (fmt-char s i 3 maximum t)) #\~)
                 (eql (the character (fmt-char s i 4 maximum t)) #\[))) (er-hard?-val? 0
                quiet
                'find-alternative-start
                "~@0"
                (illegal-fmt-msg find-alternative-start i s)))
            (t (find-alternative-start1 x s (+f i 5) maximum quiet))))))))
find-alternative-stopfunction
(defun find-alternative-stop
  (s i maximum quiet)
  (declare (type (unsigned-byte 60) i maximum)
    (type string s)
    (xargs :guard (and (<= maximum (length s)) (<= i maximum))
      :measure (nfix (- (1+ maximum) i))
      :ruler-extenders :lambdas))
  (the-fixnat (cond ((and (mbt (and (integerp i) (integerp maximum)))
         (< i (1-f maximum))) (let ((char-s-i (charf s i)))
          (declare (type character char-s-i))
          (case char-s-i
            (#\~ (let ((char-s-1+i (charf s (1+f i))))
                (declare (type character char-s-1+i))
                (case char-s-1+i
                  (#\/ i)
                  (#\[ (let ((k (find-alternative-skip s (+f 2 i) maximum quiet)))
                      (declare (type (unsigned-byte 60) k))
                      (cond ((= k 0) k)
                        (t (find-alternative-stop s k maximum quiet)))))
                  (#\] i)
                  (otherwise (find-alternative-stop s (+f 2 i) maximum quiet)))))
            (otherwise (find-alternative-stop s (+f 1 i) maximum quiet)))))
      (t (er-hard?-val? 0
          quiet
          'find-alternative-stop
          "~@0"
          (illegal-fmt-msg find-alternative-stop s))))))
punctpfunction
(defun punctp
  (c)
  (if (member c '(#\. #\, #\: #\; #\? #\! #\) #\]))
    c
    nil))
fmt-tilde-s1function
(defun fmt-tilde-s1
  (s i maximum col channel state)
  (declare (type (unsigned-byte 60) i maximum col)
    (type string s)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (<= (the-fixnat maximum) (length s))
        (open-output-channel-p channel :character state))
      :ruler-extenders :lambdas :measure (cond ((not (and (fmt-state-p state)
             (fixnat-guard i)
             (fixnat-guard maximum)
             (fixnat-guard col)
             (stringp s)
             (<= maximum (length s))
             (open-output-channel-p channel :character state)
             (< i maximum))) 0)
        ((and (> col (fmt-hard-right-margin state))
           (not (write-for-read state))) (+ 2 (nfix (* 2 (- maximum i)))))
        (t (+ 1 (nfix (* 2 (- maximum i))))))))
  (the2s (unsigned-byte 60)
    (cond ((not (mbt (and (fmt-state-p state)
             (fixnat-guard i)
             (fixnat-guard maximum)
             (fixnat-guard col)
             (stringp s)
             (<= maximum (length s))
             (open-output-channel-p channel :character state)))) (mv (nfix col) state))
      ((not (< i maximum)) (mv col state))
      ((and (> col (fmt-hard-right-margin state))
         (not (write-for-read state))) (pprogn (princ$ #\\ channel state)
          (newline channel state)
          (fmt-tilde-s1 s i maximum 0 channel state)))
      (t (let ((c (charf s i)) (fmt-soft-right-margin (fmt-soft-right-margin state)))
          (declare (type character c)
            (type (unsigned-byte 57) fmt-soft-right-margin))
          (cond ((and (> col fmt-soft-right-margin) (eql c #\ )) (pprogn (newline channel state)
                (fmt-tilde-s1 s
                  (the-fixnat (scan-past-whitespace s (+f i 1) maximum))
                  maximum
                  0
                  channel
                  state)))
            ((and (> col fmt-soft-right-margin)
               (or (eql c #\-) (eql c #\_))
               (not (= (1+f i) maximum))) (pprogn (princ$ c channel state)
                (if (eql c #\-)
                  state
                  (princ$ #\- channel state))
                (newline channel state)
                (fmt-tilde-s1 s
                  (the-fixnat (scan-past-whitespace s (+f i 1) maximum))
                  maximum
                  0
                  channel
                  state)))
            (t (pprogn (princ$ c channel state)
                (fmt-tilde-s1 s
                  (1+f i)
                  maximum
                  (cond ((eql c #\
) 0)
                    ((= col (fixnum-bound)) (fixnum-bound))
                    (t (1+f col)))
                  channel
                  state)))))))))
fmt-tilde-cap-s1function
(defun fmt-tilde-cap-s1
  (s i maximum col channel state)
  (declare (type (unsigned-byte 60) i col maximum)
    (type string s)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (<= (the-fixnat maximum) (length s))
        (open-output-channel-p channel :character state))
      :ruler-extenders :lambdas :measure (cond ((not (and (fmt-state-p state)
             (fixnat-guard i)
             (fixnat-guard maximum)
             (fixnat-guard col)
             (stringp s)
             (<= maximum (length s))
             (open-output-channel-p channel :character state)
             (< i maximum))) 0)
        (t (nfix (- maximum i))))))
  (the2s (unsigned-byte 60)
    (cond ((not (mbt (and (fmt-state-p state)
             (fixnat-guard i)
             (fixnat-guard maximum)
             (fixnat-guard col)
             (stringp s)
             (<= maximum (length s))
             (open-output-channel-p channel :character state)))) (mv 0 state))
      ((not (< i maximum)) (mv col state))
      (t (let ((c (charf s i)))
          (declare (type character c))
          (pprogn (princ$ c channel state)
            (fmt-tilde-cap-s1 s
              (1+f i)
              maximum
              (cond ((eql c #\
) 0)
                ((= col (fixnum-bound)) col)
                (t (1+f col)))
              channel
              state)))))))
fmt-varfunction
(defun fmt-var
  (s alist i maximum)
  (declare (type (unsigned-byte 60) i maximum)
    (type string s)
    (xargs :guard (and (<= maximum (length s))
        (< i maximum)
        (character-alistp alist))))
  (let* ((c (the character (fmt-char s i 2 maximum t))) (x (assoc c alist)))
    (declare (type character c))
    (cond (x (cdr x))
      (t (let ((tilde-position (if (eql (charf s i) #\~)
               i
               (1-f i))))
          (er hard?
            'fmt-var
            "~@0"
            (illegal-fmt-msg unbound-tilde-arg tilde-position c alist s)))))))
splat-atomfunction
(defun splat-atom
  (x print-base print-radix indent col channel state)
  (declare (type (unsigned-byte 5) print-base)
    (type (unsigned-byte 60) indent col)
    (type symbol channel)
    (xargs :guard (and (atom x)
        (print-base-p print-base)
        (fmt-state-p state)
        (open-output-channel-p channel :character state))))
  (the2s (unsigned-byte 60)
    (let* ((sz (flsz-atom x print-base print-radix 0 state)) (too-bigp (> (+f! col sz) (fmt-hard-right-margin state))))
      (pprogn (if too-bigp
          (pprogn (newline channel state)
            (spaces indent 0 channel state))
          state)
        (prin1$ x channel state)
        (mv (if too-bigp
            (+f! indent sz)
            (+f! col sz))
          state)))))
splat-atom!function
(defun splat-atom!
  (x print-base print-radix col channel state)
  (declare (type (unsigned-byte 5) print-base)
    (type (unsigned-byte 60) col)
    (type symbol channel)
    (xargs :guard (and (atom x)
        (print-base-p print-base)
        (open-output-channel-p channel :character state))))
  (the2s (unsigned-byte 60)
    (pprogn (prin1$ x channel state)
      (mv (flsz-atom x print-base print-radix col state) state))))
splat-stringfunction
(defun splat-string
  (x indent col channel state)
  (declare (type string x)
    (type (unsigned-byte 60) indent col)
    (type symbol channel)
    (xargs :guard (and (open-output-channel-p channel :character state)
        (fmt-state-p state))))
  (the2s (unsigned-byte 60)
    (let* ((sz (min (fixnum-bound) (length x))) (too-bigp (> (+f! col sz) (fmt-hard-right-margin state))))
      (declare (type (unsigned-byte 60) sz))
      (pprogn (if too-bigp
          (pprogn (newline channel state)
            (spaces indent 0 channel state))
          state)
        (princ$ x channel state)
        (mv (if too-bigp
            (+f! indent sz)
            (+f! col sz))
          state)))))
splatmutual-recursion
(mutual-recursion (defun splat
    (x print-base print-radix indent eviscp col channel state)
    (declare (type (unsigned-byte 5) print-base)
      (type (unsigned-byte 60) indent col)
      (type symbol channel)
      (xargs :guard (and (print-base-p print-base)
          (fmt-state-p state)
          (open-output-channel-p channel :character state))
        :ruler-extenders :lambdas :measure (1+ (* 2 (acl2-count x)))))
    (the2s (unsigned-byte 60)
      (cond ((atom x) (splat-atom x
            print-base
            print-radix
            indent
            col
            channel
            state))
        ((and (evisceratedp eviscp x) (stringp (cdr x))) (splat-string (cdr x) indent col channel state))
        ((and (eq (car x) 'quote) (consp (cdr x)) (null (cddr x))) (pprogn (princ$ #\' channel state)
            (splat (cadr x)
              print-base
              print-radix
              indent
              eviscp
              (+f! 1 col)
              channel
              state)))
        (t (pprogn (princ$ #\( channel state)
            (splat1 x
              print-base
              print-radix
              indent
              eviscp
              (+f! 1 col)
              channel
              state))))))
  (defun splat1
    (x print-base print-radix indent eviscp col channel state)
    (declare (type cons x)
      (type (unsigned-byte 5) print-base)
      (type (unsigned-byte 60) indent col)
      (type symbol channel)
      (xargs :guard (and (print-base-p print-base)
          (fmt-state-p state)
          (open-output-channel-p channel :character state))
        :ruler-extenders :lambdas :measure (* 2 (acl2-count x))))
    (the2s (unsigned-byte 60)
      (cond ((mbt (consp x)) (mv-let (col state)
            (splat (car x)
              print-base
              print-radix
              indent
              eviscp
              col
              channel
              state)
            (cond ((null (cdr x)) (pprogn (princ$ #\) channel state) (mv (+f! 1 col) state)))
              ((atom (cdr x)) (cond ((> (+f! 3 col) (fmt-hard-right-margin state)) (pprogn (newline channel state)
                      (spaces indent 0 channel state)
                      (princ$ ". " channel state)
                      (mv-let (col state)
                        (splat (cdr x)
                          print-base
                          print-radix
                          indent
                          eviscp
                          (+f! indent 2)
                          channel
                          state)
                        (pprogn (princ$ #\) channel state) (mv (+f! 1 col) state)))))
                  (t (pprogn (princ$ " . " channel state)
                      (mv-let (col state)
                        (splat (cdr x)
                          print-base
                          print-radix
                          indent
                          eviscp
                          (+f! 3 col)
                          channel
                          state)
                        (pprogn (princ$ #\) channel state) (mv (+f! 1 col) state)))))))
              (t (pprogn (princ$ #\  channel state)
                  (splat1 (cdr x)
                    print-base
                    print-radix
                    indent
                    eviscp
                    (+f! 1 col)
                    channel
                    state))))))
        (t (mv 0 state))))))
number-of-digitsfunction
(defun number-of-digits
  (n print-base print-radix)
  (declare (type (unsigned-byte 5) print-base)
    (type integer n)
    (xargs :guard (print-base-p print-base)
      :measure (cond ((not (and (integerp n) (print-base-p print-base))) 0)
        ((< n 0) (1+ (- n)))
        (t n))
      :ruler-extenders :lambdas))
  (the-fixnat (cond ((not (mbt (and (integerp n) (print-base-p print-base)))) 0)
      ((< n 0) (+f! 1 (number-of-digits (abs n) print-base print-radix)))
      ((< n print-base) (cond ((null print-radix) 1) ((= print-base 10) 2) (t 3)))
      (t (+f! 1
          (number-of-digits (floor n print-base)
            print-base
            print-radix))))))
left-pad-with-blanksfunction
(defun left-pad-with-blanks
  (n width col channel state)
  (declare (type integer n)
    (type (integer 0 *) width)
    (type (unsigned-byte 60) col)
    (type symbol channel)
    (xargs :guard (and (open-output-channel-p channel :character state)
        (fmt-state-p state))))
  (the2s (unsigned-byte 60)
    (cond ((> width (fixnum-bound)) (prog2$ (er hard?
            'left-pad-with-blanks
            "It is illegal to supply a padding width of greater than ~x0."
            (fixnum-bound))
          (mv (fixnum-bound) state)))
      (t (let ((d (number-of-digits n (print-base) (print-radix))))
          (declare (type (unsigned-byte 60) d))
          (cond ((>= d width) (pprogn (prin1$ n channel state) (mv (+f! col d) state)))
            (t (pprogn (spaces (-f (the-fixnat width) d) col channel state)
                (prin1$ n channel state)
                (mv (+f! col width) state)))))))))
maybe-newlinemacro
(defmacro maybe-newline
  (body)
  `(mv-letc (col state)
    (cond ((and (> col (fmt-hard-right-margin state))
         (not (write-for-read state))) (pprogn (princ$ #\\ channel state)
          (newline channel state)
          (mv 0 state)))
      (t (mv col state)))
    ,BODY))
evisc-tuplefunction
(defun evisc-tuple
  (print-level print-length alist hiding-cars)
  (list alist print-level print-length hiding-cars))
world-evisceration-alistfunction
(defun world-evisceration-alist
  (state alist)
  (declare (xargs :stobjs state))
  (let ((wrld (w state)))
    (cond ((null wrld) alist)
      (t (cons (cons wrld *evisceration-world-mark*) alist)))))
abbrev-evisc-tuplefunction
(defun abbrev-evisc-tuple
  (state)
  (declare (xargs :guard t))
  (let ((evisc-tuple (f-get-global 'abbrev-evisc-tuple state)))
    (cond ((eq evisc-tuple :default) (cons (world-evisceration-alist state nil) '(5 7 nil)))
      (t evisc-tuple))))
gag-modemacro
(defmacro gag-mode nil '(f-get-global 'gag-mode state))
term-evisc-tuplefunction
(defun term-evisc-tuple
  (flg state)
  (let ((evisc-tuple (f-get-global 'term-evisc-tuple state)))
    (cond ((not (eq evisc-tuple :default)) evisc-tuple)
      ((f-get-global 'eviscerate-hide-terms state) (cond (flg '(nil 3 4 (hide))) (t '(nil nil nil (hide)))))
      (flg '(nil 3 4 nil))
      (t nil))))
gag-mode-evisc-tuplefunction
(defun gag-mode-evisc-tuple
  (state)
  (cond ((gag-mode) (let ((val (f-get-global 'gag-mode-evisc-tuple state)))
        (if (eq val :default)
          nil
          val)))
    (t (term-evisc-tuple nil state))))
ld-evisc-tuplefunction
(defun ld-evisc-tuple
  (state)
  (let ((evisc-tuple (f-get-global 'ld-evisc-tuple state)))
    (assert$ (not (eq evisc-tuple :default)) evisc-tuple)))
brr-evisc-tuplefunction
(defun brr-evisc-tuple
  (state)
  (let ((val (f-get-global 'brr-evisc-tuple state)))
    (cond ((eq val :default) (term-evisc-tuple t state))
      (t val))))
fmt-pprfunction
(defun fmt-ppr
  (x width rpc col channel state eviscp)
  (declare (type (unsigned-byte 60) width rpc col)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (open-output-channel-p channel :character state))))
  (ppr2 (ppr1 x
      (print-base)
      (print-radix)
      (round-to-small t width)
      (round-to-small t rpc)
      state
      eviscp)
    (round-to-small t col)
    channel
    state
    eviscp))
scan-past-empty-fmt-directives1function
(defun scan-past-empty-fmt-directives1
  (s alist i maximum clk)
  (declare (type (unsigned-byte 60) i maximum clk)
    (type string s)
    (xargs :ruler-extenders :lambdas :verify-guards nil
      :guard (and (<= maximum (length s)) (character-alistp alist))))
  (the-fixnat (cond ((or (not (mbt (and (natp i)
               (natp maximum)
               (<= maximum (length s))
               (<= maximum (fixnum-bound)))))
         (>= i maximum)
         (zp clk)) (min (fixnum-bound) (nfix i)))
      (t (let ((c (charf s i)))
          (declare (type character c))
          (cond ((eql c #\~) (let ((fmc (the character (fmt-char s i 1 maximum t))))
                (declare (type character fmc))
                (case fmc
                  ((#\s #\S) (cond ((equal (fmt-var s alist i maximum) "") (scan-past-empty-fmt-directives1 s
                          alist
                          (+f! i 3)
                          maximum
                          (1-f clk)))
                      (t i)))
                  (#\@ (let ((val (fmt-var s alist i maximum)))
                      (cond ((not (msgp val)) (er-hard?-val? i
                            nil
                            'scan-past-empty-fmt-directives1
                            "~@0"
                            (illegal-fmt-msg bad-tilde-@-arg i val 'msgp s)))
                        ((equal val "") (scan-past-empty-fmt-directives1 s
                            alist
                            (+f! i 3)
                            maximum
                            (1-f clk)))
                        ((stringp val) i)
                        ((equal (car val) "") (scan-past-empty-fmt-directives1 s
                            alist
                            (+f! i 3)
                            maximum
                            (1-f clk)))
                        (t (let ((len (length (car val))) (alist1 (append (cdr val) alist)))
                            (if (and (<= len (fixnum-bound))
                                (equal (scan-past-empty-fmt-directives1 (car val)
                                    alist1
                                    0
                                    len
                                    (1-f clk))
                                  len))
                              (scan-past-empty-fmt-directives1 s
                                alist
                                (+f! i 3)
                                maximum
                                (1-f clk))
                              i))))))
                  (#\# (let* ((n (find-alternative-start (fmt-var s alist i maximum)
                           s
                           i
                           maximum
                           nil)) (m (if (= n 0)
                            0
                            (find-alternative-stop s n maximum nil)))
                        (o (if (= m 0)
                            0
                            (find-alternative-skip s m maximum nil))))
                      (declare (type (unsigned-byte 60) n)
                        (type (unsigned-byte 60) m o))
                      (cond ((= o 0) 0)
                        ((or (= n m)
                           (= (scan-past-empty-fmt-directives1 s alist n m (1-f clk))
                             m)) (scan-past-empty-fmt-directives1 s
                            alist
                            o
                            maximum
                            (1-f clk)))
                        (t i))))
                  (otherwise i))))
            (t i)))))))
scan-past-empty-fmt-directivesfunction
(defun scan-past-empty-fmt-directives
  (s alist i maximum)
  (declare (type (unsigned-byte 60) i maximum)
    (type string s)
    (xargs :guard (and (<= maximum (length s)) (character-alistp alist))))
  (scan-past-empty-fmt-directives1 s
    alist
    i
    maximum
    (fixnum-bound)))
other
(defun-inline min-fixnat
  (x y)
  (declare (type (unsigned-byte 60) x y))
  (the (unsigned-byte 60)
    (if (< x y)
      x
      y)))
out-of-time-the2sfunction
(defun out-of-time-the2s
  (fn state)
  (declare (xargs :stobjs state))
  (the2s (unsigned-byte 60)
    (prog2$ (er hard? fn "Clock ran out in ~x0!" fn)
      (mv 0 state))))
char?function
(defun char?
  (s i)
  (declare (xargs :guard (and (stringp s) (natp i))))
  (the character
    (if (and (mbt (natp i)) (< i (length s)))
      (char s i)
      (prog2$ (er hard?
          'char?
          "Unexpected out of bounds index ~x0 for string ~s1!"
          i
          s)
        *null-char*))))
fmt0*mutual-recursion
(mutual-recursion (defun fmt0*
    (str0 str1
      str2
      str3
      lst
      alist
      col
      channel
      state
      evisc-tuple
      clk)
    (declare (type (unsigned-byte 60) col clk)
      (type string str0 str1 str2 str3)
      (type symbol channel)
      (xargs :guard (and (fixnat-guard (length str0))
          (fixnat-guard (length str1))
          (fixnat-guard (length str2))
          (fixnat-guard (length str3))
          (true-listp lst)
          (character-alistp alist)
          (fmt-state-p state)
          (open-output-channel-p channel :character state)
          (standard-evisc-tuplep evisc-tuple))
        :measure (nfix clk)
        :ruler-extenders :lambdas :verify-guards nil))
    (the2s (unsigned-byte 60)
      (cond ((zp clk) (out-of-time-the2s 'fmt0* state))
        ((not (mbt (fixnat-guard col))) (mv 0 state))
        ((endp lst) (fmt0 str0
            alist
            0
            (length str0)
            col
            nil
            channel
            state
            evisc-tuple
            (1-f clk)))
        ((null (cdr lst)) (fmt0 str1
            (cons (cons #\* (car lst)) alist)
            0
            (length str1)
            col
            nil
            channel
            state
            evisc-tuple
            (1-f clk)))
        ((null (cddr lst)) (mv-letc (col state)
            (fmt0 str2
              (cons (cons #\* (car lst)) alist)
              0
              (length str2)
              col
              nil
              channel
              state
              evisc-tuple
              (1-f clk))
            (fmt0* str0
              str1
              str2
              str3
              (cdr lst)
              alist
              col
              channel
              state
              evisc-tuple
              (1-f clk))))
        (t (mv-letc (col state)
            (fmt0 str3
              (cons (cons #\* (car lst)) alist)
              0
              (length str3)
              col
              nil
              channel
              state
              evisc-tuple
              (1-f clk))
            (fmt0* str0
              str1
              str2
              str3
              (cdr lst)
              alist
              col
              channel
              state
              evisc-tuple
              (1-f clk)))))))
  (defun fmt0&v
    (flg lst punct col channel state evisc-tuple clk)
    (declare (type (unsigned-byte 60) col clk)
      (type symbol channel)
      (xargs :guard (and (true-listp lst)
          (fmt-state-p state)
          (open-output-channel-p channel :character state)
          (standard-evisc-tuplep evisc-tuple))
        :measure (nfix clk)
        :ruler-extenders :lambdas))
    (the2s (unsigned-byte 60)
      (cond ((zp clk) (out-of-time-the2s 'fmt0&v state))
        ((not (mbt (fixnat-guard col))) (mv 0 state))
        (t (case flg
            (& (case punct
                (#\. (fmt0* ""
                    "~x*."
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\, (fmt0* ""
                    "~x*,"
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\: (fmt0* ""
                    "~x*:"
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\; (fmt0* ""
                    "~x*;"
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\? (fmt0* ""
                    "~x*?"
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\! (fmt0* ""
                    "~x*!"
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\) (fmt0* ""
                    "~x*)"
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\] (fmt0* ""
                    "~x*]"
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                ((nil) (fmt0* ""
                    "~x*"
                    "~x* and "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (otherwise (prog2$ (er hard?
                      'fmt0&v
                      "Implementation error: Missing punctp case, ~x0"
                      punct)
                    (mv 0 state)))))
            (otherwise (case punct
                (#\. (fmt0* ""
                    "~x*."
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\, (fmt0* ""
                    "~x*,"
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\: (fmt0* ""
                    "~x*:"
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\; (fmt0* ""
                    "~x*;"
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\? (fmt0* ""
                    "~x*?"
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\! (fmt0* ""
                    "~x*!"
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\) (fmt0* ""
                    "~x*)"
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (#\] (fmt0* ""
                    "~x*]"
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                ((nil) (fmt0* ""
                    "~x*"
                    "~x* or "
                    "~x*, "
                    lst
                    nil
                    col
                    channel
                    state
                    evisc-tuple
                    (1-f clk)))
                (otherwise (prog2$ (er hard?
                      'fmt0&v
                      "Implementation error: Missing punctp case, ~x0"
                      punct)
                    (mv 0 state))))))))))
  (defun spell-number
    (n cap col channel state evisc-tuple clk)
    (declare (type (unsigned-byte 60) col clk)
      (type symbol channel)
      (xargs :guard (and (or (integerp n) (and (consp n) (integerp (car n))))
          (fmt-state-p state)
          (open-output-channel-p channel :character state)
          (standard-evisc-tuplep evisc-tuple))
        :measure (nfix clk)
        :ruler-extenders :lambdas))
    (the2s (unsigned-byte 60)
      (cond ((zp clk) (out-of-time-the2s 'spell-number state))
        ((not (mbt (fixnat-guard col))) (mv 0 state))
        (t (let ((str (cond ((integerp n) (cond ((int= n 0) (if cap
                         "Zero"
                         "zero"))
                     ((int= n 1) (if cap
                         "One"
                         "one"))
                     ((int= n 2) (if cap
                         "Two"
                         "two"))
                     ((int= n 3) (if cap
                         "Three"
                         "three"))
                     ((int= n 4) (if cap
                         "Four"
                         "four"))
                     ((int= n 5) (if cap
                         "Five"
                         "five"))
                     ((int= n 6) (if cap
                         "Six"
                         "six"))
                     ((int= n 7) (if cap
                         "Seven"
                         "seven"))
                     ((int= n 8) (if cap
                         "Eight"
                         "eight"))
                     ((int= n 9) (if cap
                         "Nine"
                         "nine"))
                     ((int= n 10) (if cap
                         "Ten"
                         "ten"))
                     ((int= n 11) (if cap
                         "Eleven"
                         "eleven"))
                     ((int= n 12) (if cap
                         "Twelve"
                         "twelve"))
                     ((int= n 13) (if cap
                         "Thirteen"
                         "thirteen"))
                     (t "~x0")))
                 ((and (consp n) (<= 0 (car n)) (<= (car n) 13)) (cond ((int= (car n) 0) (if cap
                         "Zeroth"
                         "zeroth"))
                     ((int= (car n) 1) (if cap
                         "First"
                         "first"))
                     ((int= (car n) 2) (if cap
                         "Second"
                         "second"))
                     ((int= (car n) 3) (if cap
                         "Third"
                         "third"))
                     ((int= (car n) 4) (if cap
                         "Fourth"
                         "fourth"))
                     ((int= (car n) 5) (if cap
                         "Fifth"
                         "fifth"))
                     ((int= (car n) 6) (if cap
                         "Sixth"
                         "sixth"))
                     ((int= (car n) 7) (if cap
                         "Seventh"
                         "seventh"))
                     ((int= (car n) 8) (if cap
                         "Eighth"
                         "eighth"))
                     ((int= (car n) 9) (if cap
                         "Ninth"
                         "ninth"))
                     ((int= (car n) 10) (if cap
                         "Tenth"
                         "tenth"))
                     ((int= (car n) 11) (if cap
                         "Eleventh"
                         "eleventh"))
                     ((int= (car n) 12) (if cap
                         "Twelfth"
                         "twelfth"))
                     (t (if cap
                         "Thirteenth"
                         "thirteenth"))))
                 (t (let ((d (mod (abs (car n)) 10)))
                     (cond ((or (int= d 0)
                          (> d 3)
                          (int= (car n) -11)
                          (int= (car n) -12)
                          (int= (car n) -13)) "~x0th")
                       ((int= d 1) "~x0st")
                       ((int= d 2) "~x0nd")
                       (t "~x0rd")))))))
            (declare (type string str))
            (fmt0 (the-string! str 'spell-number)
              (cond ((integerp n) (cond ((and (<= 0 n) (<= n 13)) nil)
                    (t (list (cons #\0 n)))))
                (t (cond ((and (<= 0 (car n)) (<= (car n) 13)) nil)
                    (t (list (cons #\0 (car n)))))))
              0
              (the-fixnat! (length str) 'spell-number)
              col
              nil
              channel
              state
              evisc-tuple
              (1-f clk)))))))
  (defun fmt-tilde-s
    (s col channel state clk)
    (declare (type (unsigned-byte 60) col clk)
      (type symbol channel)
      (xargs :guard (and (or (symbolp s) (stringp s) (acl2-numberp s))
          (fmt-state-p state)
          (open-output-channel-p channel :character state))
        :measure (nfix clk)
        :ruler-extenders :lambdas))
    (the2s (unsigned-byte 60)
      (cond ((zp clk) (out-of-time-the2s 'fmt-tilde-s state))
        ((not (mbt (fixnat-guard col))) (mv 0 state))
        ((acl2-numberp s) (pprogn (prin1$ s channel state)
            (mv (flsz-atom s (print-base) (print-radix) col state)
              state)))
        ((stringp s) (fmt-tilde-s1 s
            0
            (the-fixnat! (length s) 'fmt-tilde-s)
            col
            channel
            state))
        (t (let ((str (symbol-name s)))
            (cond ((keywordp s) (cond ((needs-slashes str state) (splat-atom s
                      (print-base)
                      (print-radix)
                      0
                      col
                      channel
                      state))
                  (t (fmt0 ":~s0"
                      (list (cons #\0 str))
                      0
                      4
                      col
                      nil
                      channel
                      state
                      nil
                      (1-f clk)))))
              ((symbol-in-current-package-p s state) (cond ((needs-slashes str state) (splat-atom s
                      (print-base)
                      (print-radix)
                      0
                      col
                      channel
                      state))
                  (t (fmt-tilde-s1 str
                      0
                      (the-fixnat! (length str) 'fmt-tilde-s)
                      col
                      channel
                      state))))
              (t (let ((p (symbol-package-name s)))
                  (cond ((or (needs-slashes p state) (needs-slashes str state)) (splat-atom s
                        (print-base)
                        (print-radix)
                        0
                        col
                        channel
                        state))
                    (t (fmt0 "~s0::~-~s1"
                        (list (cons #\0 p) (cons #\1 str))
                        0
                        10
                        col
                        nil
                        channel
                        state
                        nil
                        (1-f clk))))))))))))
  (defun fmt-tilde-cap-s
    (s col channel state clk)
    (declare (type (unsigned-byte 60) col clk)
      (type symbol channel)
      (xargs :guard (and (or (symbolp s) (stringp s) (acl2-numberp s))
          (fmt-state-p state)
          (open-output-channel-p channel :character state))
        :measure (nfix clk)
        :ruler-extenders :lambdas))
    (the2s (unsigned-byte 60)
      (cond ((zp clk) (out-of-time-the2s 'fmt-tilde-cap-s state))
        ((not (mbt (fixnat-guard col))) (mv 0 state))
        ((acl2-numberp s) (splat-atom! s (print-base) (print-radix) col channel state))
        ((stringp s) (fmt-tilde-cap-s1 s
            0
            (the-fixnat! (length s) 'fmt-tilde-s)
            col
            channel
            state))
        (t (let ((str (symbol-name s)))
            (cond ((keywordp s) (cond ((needs-slashes str state) (splat-atom! s (print-base) (print-radix) col channel state))
                  (t (fmt0 ":~S0"
                      (list (cons #\0 str))
                      0
                      4
                      col
                      nil
                      channel
                      state
                      nil
                      (1-f clk)))))
              ((symbol-in-current-package-p s state) (cond ((needs-slashes str state) (splat-atom! s (print-base) (print-radix) col channel state))
                  (t (fmt-tilde-cap-s1 str
                      0
                      (the-fixnat! (length str) 'fmt-tilde-s)
                      col
                      channel
                      state))))
              (t (let ((p (symbol-package-name s)))
                  (cond ((or (needs-slashes p state) (needs-slashes str state)) (splat-atom! s (print-base) (print-radix) col channel state))
                    (t (fmt0 "~S0::~S1"
                        (list (cons #\0 p) (cons #\1 str))
                        0
                        8
                        col
                        nil
                        channel
                        state
                        nil
                        (1-f clk))))))))))))
  (defun fmt0
    (s alist i maximum col pn channel state evisc-tuple clk)
    (declare (type (unsigned-byte 60) i maximum col clk)
      (type atom pn)
      (type string s)
      (type symbol channel)
      (xargs :guard (and (fmt-state-p state)
          (<= (the-fixnat maximum) (length s))
          (character-alistp alist)
          (open-output-channel-p channel :character state)
          (standard-evisc-tuplep evisc-tuple))
        :measure (nfix clk)
        :ruler-extenders :lambdas))
    (the2s (unsigned-byte 60)
      (cond ((zp clk) (out-of-time-the2s 'fmt0 state))
        ((not (mbt (fixnat-guard col))) (mv 0 state))
        ((>= i maximum) (cond (pn (pprogn (princ$ pn channel state) (mv (+f! 1 col) state)))
            (t (mv col state))))
        (t (let ((c (charf s i)))
            (declare (type character c))
            (cond ((eql c #\~) (let ((fmc (fmt-char s i 1 maximum t)))
                  (declare (type character fmc))
                  (case fmc
                    ((#\p #\q #\P #\Q #\x #\y #\X #\Y) (maybe-newline (let* ((caps (or (eql fmc #\P) (eql fmc #\Q) (eql fmc #\X) (eql fmc #\Y))) (px (or (eql fmc #\p) (eql fmc #\P) (eql fmc #\x) (eql fmc #\X)))
                            (qy (not px))
                            (local-evisc-tuple (cond (caps (let ((x (fmt-var s alist (1+f i) maximum)))
                                    (cond ((not (standard-evisc-tuplep x)) (er-hard?-val? nil
                                          nil
                                          'fmt0
                                          "~@0"
                                          (illegal-fmt-msg bad-evisc-tuple
                                            i
                                            (char? s (+f! i 3))
                                            x
                                            'standard-evisc-tuplep
                                            s)))
                                      (t x))))
                                (t evisc-tuple)))
                            (evisc-table (table-alist 'evisc-table (w state)))
                            (eviscp (or local-evisc-tuple evisc-table)))
                          (mv-let (x state)
                            (cond (eviscp (eviscerate-top (fmt-var s alist i maximum)
                                  (cadr local-evisc-tuple)
                                  (caddr local-evisc-tuple)
                                  (car local-evisc-tuple)
                                  evisc-table
                                  (cadddr local-evisc-tuple)
                                  state))
                              (t (mv (fmt-var s alist i maximum) state)))
                            (let* ((fmt-hard-right-margin (fmt-hard-right-margin state)) (sz (flsz x col fmt-hard-right-margin state eviscp))
                                (incr (the-fixnat (if caps
                                      4
                                      3)))
                                (c (fmt-char s i incr maximum nil))
                                (punctp (punctp c))
                                (print-pn (and pn (not punctp) (= (+f! i incr) maximum)))
                                (p+ (if (or punctp print-pn)
                                    1
                                    0)))
                              (declare (type (unsigned-byte 57) fmt-hard-right-margin)
                                (type (unsigned-byte 60) sz incr p+)
                                (type character c))
                              (cond ((and px
                                   (> col (the-fixnat *fmt-ppr-indentation*))
                                   (> (+f! p+ sz) fmt-hard-right-margin)
                                   (not (> (+f! p+
                                         (flsz x
                                           (the-fixnat *fmt-ppr-indentation*)
                                           fmt-hard-right-margin
                                           state
                                           eviscp))
                                       fmt-hard-right-margin))) (pprogn (newline channel state)
                                    (spaces1 (the-fixnat *fmt-ppr-indentation*)
                                      0
                                      fmt-hard-right-margin
                                      channel
                                      state)
                                    (fmt0 s
                                      alist
                                      i
                                      maximum
                                      (the-fixnat *fmt-ppr-indentation*)
                                      pn
                                      channel
                                      state
                                      evisc-tuple
                                      (1-f clk))))
                                ((or qy (> (+f! p+ sz) fmt-hard-right-margin)) (pprogn (cond (qy state)
                                      ((= col 0) state)
                                      (t (newline channel state)))
                                    (if qy
                                      state
                                      (spaces1 (the-fixnat *fmt-ppr-indentation*)
                                        0
                                        fmt-hard-right-margin
                                        channel
                                        state))
                                    (let* ((i1 (the-fixnat (if punctp
                                             (+f! i 1 incr)
                                             (+f! i incr)))) (i2 (if qy
                                            i1
                                            (scan-past-whitespace s i1 maximum)))
                                        (new-col (min-fixnat fmt-hard-right-margin
                                            (if qy
                                              col
                                              *fmt-ppr-indentation*))))
                                      (declare (type (unsigned-byte 60) i1 i2 new-col))
                                      (pprogn (fmt-ppr x
                                          (-f fmt-hard-right-margin new-col)
                                          p+
                                          new-col
                                          channel
                                          state
                                          eviscp)
                                        (cond (punctp (princ$ c channel state))
                                          (print-pn (princ$ pn channel state))
                                          (t state))
                                        (newline channel state)
                                        (fmt0 s
                                          alist
                                          i2
                                          maximum
                                          0
                                          (and (not print-pn) pn)
                                          channel
                                          state
                                          evisc-tuple
                                          (1-f clk))))))
                                (t (pprogn (flpr x channel state eviscp)
                                    (fmt0 s
                                      alist
                                      (+f! i
                                        (if caps
                                          4
                                          3))
                                      maximum
                                      sz
                                      pn
                                      channel
                                      state
                                      evisc-tuple
                                      (1-f clk))))))))))
                    (#\@ (let ((s1 (fmt-var s alist i maximum)) (i0 (scan-past-empty-fmt-directives s alist (+f! i 3) maximum)))
                        (declare (type (unsigned-byte 60) i0))
                        (mv-let (i1 pn pn@)
                          (cond ((< i0 maximum) (let ((punctp (punctp (charf s i0))))
                                (cond (punctp (mv (+f 1 i0) pn punctp)) (t (mv i0 pn nil)))))
                            (t (mv i0 nil pn)))
                          (declare (type (unsigned-byte 60) i1))
                          (mv-letc (col state)
                            (cond ((stringp s1) (fmt0 s1
                                  alist
                                  0
                                  (the-fixnat! (length s1) 'fmt0)
                                  col
                                  pn@
                                  channel
                                  state
                                  evisc-tuple
                                  (1-f clk)))
                              ((msgp s1) (fmt0 (car s1)
                                  (append (cdr s1) alist)
                                  0
                                  (the-fixnat! (length (car s1)) 'fmt0)
                                  col
                                  pn@
                                  channel
                                  state
                                  evisc-tuple
                                  (1-f clk)))
                              (t (mv (er-hard-val 0
                                    'fmt0
                                    "~@0"
                                    (illegal-fmt-msg bad-tilde-@-arg i s1 'msgp s))
                                  state)))
                            (fmt0 s
                              alist
                              i1
                              maximum
                              col
                              pn
                              channel
                              state
                              evisc-tuple
                              (1-f clk))))))
                    (#\# (let* ((n (find-alternative-start (fmt-var s alist i maximum)
                             s
                             i
                             maximum
                             nil)) (m (find-alternative-stop s n maximum nil))
                          (o (find-alternative-skip s m maximum nil)))
                        (declare (type (unsigned-byte 60) n)
                          (type (unsigned-byte 60) m o))
                        (mv-let (pn1 pn2 o)
                          (cond ((= o maximum) (mv pn nil o))
                            ((punctp (charf s o)) (mv (charf s o) pn (1+f o)))
                            (t (mv nil pn o)))
                          (declare (type (unsigned-byte 60) o))
                          (mv-letc (col state)
                            (fmt0 s
                              alist
                              n
                              m
                              col
                              pn1
                              channel
                              state
                              evisc-tuple
                              (1-f clk))
                            (fmt0 s
                              alist
                              o
                              maximum
                              col
                              pn2
                              channel
                              state
                              evisc-tuple
                              (1-f clk))))))
                    (#\* (let ((x (fmt-var s alist i maximum)))
                        (cond ((or (< (len x) 5)
                             (not (and (stringp (car x))
                                 (fixnat-guard (length (car x)))
                                 (stringp (cadr x))
                                 (fixnat-guard (length (cadr x)))
                                 (stringp (caddr x))
                                 (fixnat-guard (length (caddr x)))
                                 (stringp (cadddr x))
                                 (fixnat-guard (length (cadddr x)))
                                 (true-listp (car (cddddr x)))
                                 (character-alistp (cdr (cddddr x)))))) (mv (er-hard-val 0
                                'fmt0
                                "~@0"
                                (illegal-fmt-msg bad-tilde-*-arg
                                  i
                                  (char? s (+f! i 2))
                                  'character-alistp
                                  x
                                  s))
                              state))
                          (t (mv-letc (col state)
                              (fmt0* (car x)
                                (cadr x)
                                (caddr x)
                                (cadddr x)
                                (car (cddddr x))
                                (append (cdr (cddddr x)) alist)
                                col
                                channel
                                state
                                evisc-tuple
                                (1-f clk))
                              (fmt0 s
                                alist
                                (+f! i 3)
                                maximum
                                col
                                pn
                                channel
                                state
                                evisc-tuple
                                (1-f clk)))))))
                    ((#\& #\v) (let ((i+3 (+f! i 3)) (lst (fmt-var s alist i maximum)))
                        (declare (type (unsigned-byte 60) i+3))
                        (cond ((not (true-listp lst)) (mv (er-hard-val 0
                                'fmt0
                                "~@0"
                                (illegal-fmt-msg bad-tilde-&v-arg
                                  i
                                  (char? s (+f! i 2))
                                  (if (eql fmc #\&)
                                    "~&"
                                    "~v")
                                  lst
                                  s))
                              state))
                          (t (mv-letc (col state)
                              (fmt0&v (if (eql fmc #\&)
                                  '&
                                  'v)
                                lst
                                (punctp (and (< i+3 maximum) (char s i+3)))
                                col
                                channel
                                state
                                evisc-tuple
                                (1-f clk))
                              (fmt0 s
                                alist
                                (the-fixnat (cond ((punctp (and (< i+3 maximum) (char s i+3))) (+f! i 4))
                                    (t i+3)))
                                maximum
                                col
                                pn
                                channel
                                state
                                evisc-tuple
                                (1-f clk)))))))
                    ((#\n #\N) (let ((k (fmt-var s alist i maximum)))
                        (cond ((not (or (integerp k) (and (consp k) (integerp (car k))))) (mv (er-hard-val 0
                                'fmt0
                                "~@0"
                                (illegal-fmt-msg bad-tilde-n-arg
                                  i
                                  (char? s (+f! i 2))
                                  (if (eql fmc #\n)
                                    "~n"
                                    "~N")
                                  k
                                  s))
                              state))
                          (t (maybe-newline (mv-letc (col state)
                                (spell-number k
                                  (eql fmc #\N)
                                  col
                                  channel
                                  state
                                  evisc-tuple
                                  (1-f clk))
                                (fmt0 s
                                  alist
                                  (+f! i 3)
                                  maximum
                                  col
                                  pn
                                  channel
                                  state
                                  evisc-tuple
                                  (1-f clk))))))))
                    (#\t (maybe-newline (let ((goal-col (fmt-var s alist i maximum)) (fmt-hard-right-margin (fmt-hard-right-margin state)))
                          (declare (type (unsigned-byte 57) fmt-hard-right-margin))
                          (cond ((or (not (natp goal-col))
                               (> goal-col fmt-hard-right-margin)) (prog2$ (if (natp goal-col)
                                  (er hard?
                                    'fmt0
                                    "~@0"
                                    (illegal-fmt-msg bad-tilde-t-arg-natp
                                      fmt-hard-right-margin
                                      (string (fmt-char s i 2 maximum t))
                                      goal-col))
                                  (er hard?
                                    'fmt0
                                    "~@0"
                                    (illegal-fmt-msg bad-tilde-t-arg-not-natp
                                      i
                                      (char? s (+f! i 2))
                                      goal-col
                                      s)))
                                (mv col state)))
                            (t (pprogn (cond ((>= col (the-fixnat goal-col)) (pprogn (newline channel state)
                                      (spaces1 (the-fixnat goal-col)
                                        0
                                        fmt-hard-right-margin
                                        channel
                                        state)))
                                  (t (spaces1 (-f goal-col col)
                                      col
                                      fmt-hard-right-margin
                                      channel
                                      state)))
                                (fmt0 s
                                  alist
                                  (+f! i 3)
                                  maximum
                                  (the-fixnat goal-col)
                                  pn
                                  channel
                                  state
                                  evisc-tuple
                                  (1-f clk))))))))
                    (#\c (maybe-newline (let ((pair (fmt-var s alist i maximum)))
                          (cond ((and (consp pair)
                               (integerp (car pair))
                               (integerp (cdr pair))
                               (>= (cdr pair) 0)) (mv-letc (col state)
                                (left-pad-with-blanks (car pair)
                                  (cdr pair)
                                  col
                                  channel
                                  state)
                                (fmt0 s
                                  alist
                                  (+f! i 3)
                                  maximum
                                  col
                                  pn
                                  channel
                                  state
                                  evisc-tuple
                                  (1-f clk))))
                            (t (mv (er-hard-val 0
                                  'fmt0
                                  "~@0"
                                  (illegal-fmt-msg bad-tilde-c-arg i pair s))
                                state))))))
                    ((#\f #\F) (let ((evisc-table (append? (car evisc-tuple)
                             (table-alist 'evisc-table (w state)))))
                        (mv-let (x state)
                          (cond (evisc-table (eviscerate-top (fmt-var s alist i maximum)
                                nil
                                nil
                                nil
                                evisc-table
                                nil
                                state))
                            (t (mv (fmt-var s alist i maximum) state)))
                          (maybe-newline (mv-letc (col state)
                              (splat x
                                (print-base)
                                (print-radix)
                                (if (eql fmc #\F)
                                  (+f! 1 col)
                                  0)
                                evisc-table
                                col
                                channel
                                state)
                              (fmt0 s
                                alist
                                (+f! i 3)
                                maximum
                                col
                                pn
                                channel
                                state
                                evisc-tuple
                                (1-f clk)))))))
                    ((#\s #\S) (let ((x (fmt-var s alist i maximum)))
                        (cond ((or (symbolp x) (stringp x) (acl2-numberp x)) (maybe-newline (mv-letc (col state)
                                (if (eql fmc #\s)
                                  (fmt-tilde-s x col channel state (1-f clk))
                                  (fmt-tilde-cap-s x col channel state (1-f clk)))
                                (fmt0 s
                                  alist
                                  (+f! i 3)
                                  maximum
                                  (min col (fixnum-bound))
                                  pn
                                  channel
                                  state
                                  evisc-tuple
                                  (1-f clk)))))
                          (t (mv (er-hard-val 0
                                'fmt0
                                "~@0"
                                (illegal-fmt-msg bad-tilde-s-arg
                                  (if (eql fmc #\s)
                                    "s"
                                    "S")
                                  i
                                  x
                                  s))
                              state)))))
                    (#\  (let ((exceeds-margin (or (> col (fmt-hard-right-margin state))
                             (> col (fmt-soft-right-margin state)))))
                        (pprogn (cond (exceeds-margin (newline channel state)) (t state))
                          (princ$ #\  channel state)
                          (fmt0 s
                            alist
                            (+f! i 2)
                            maximum
                            (cond (exceeds-margin 1) (t (1+f col)))
                            pn
                            channel
                            state
                            evisc-tuple
                            (1-f clk)))))
                    (#\_ (maybe-newline (let ((fmt-hard-right-margin (fmt-hard-right-margin state)))
                          (declare (type (unsigned-byte 57) fmt-hard-right-margin))
                          (let* ((n0 (fmt-var s alist i maximum)) (n (if (and (natp n0) (<= n0 (floor (fixnum-bound) 2)))
                                  n0
                                  (er-hard-val 0
                                    'fmt0
                                    "~@0"
                                    (illegal-fmt-msg bad-tilde-_-arg
                                      i
                                      n0
                                      (floor (fixnum-bound) 2)
                                      s)))))
                            (declare (type (unsigned-byte 60) n))
                            (let ((new-col (+f! col n)))
                              (declare (type (unsigned-byte 60) new-col))
                              (pprogn (spaces n col channel state)
                                (cond ((> new-col fmt-hard-right-margin) (newline channel state))
                                  (t state))
                                (fmt0 s
                                  alist
                                  (+f! i 3)
                                  maximum
                                  (the-fixnat (cond ((> new-col fmt-hard-right-margin) 0) (t new-col)))
                                  pn
                                  channel
                                  state
                                  evisc-tuple
                                  (1-f clk))))))))
                    (#\
 (fmt0 s
                        alist
                        (scan-past-whitespace s (+f! i 2) maximum)
                        maximum
                        col
                        pn
                        channel
                        state
                        evisc-tuple
                        (1-f clk)))
                    (#\| (pprogn (if (int= col 0)
                          state
                          (newline channel state))
                        (fmt0 s
                          alist
                          (+f! i 2)
                          maximum
                          0
                          pn
                          channel
                          state
                          evisc-tuple
                          (1-f clk))))
                    (#\% (pprogn (newline channel state)
                        (fmt0 s
                          alist
                          (+f! i 2)
                          maximum
                          0
                          pn
                          channel
                          state
                          evisc-tuple
                          (1-f clk))))
                    (#\~ (maybe-newline (pprogn (princ$ #\~ channel state)
                          (fmt0 s
                            alist
                            (+f! i 2)
                            maximum
                            (+f! 1 col)
                            pn
                            channel
                            state
                            evisc-tuple
                            (1-f clk)))))
                    (#\- (cond ((> col (fmt-soft-right-margin state)) (pprogn (princ$ #\- channel state)
                            (newline channel state)
                            (fmt0 s
                              alist
                              (scan-past-whitespace s (+f! i 2) maximum)
                              maximum
                              0
                              pn
                              channel
                              state
                              evisc-tuple
                              (1-f clk))))
                        (t (fmt0 s
                            alist
                            (+f! i 2)
                            maximum
                            col
                            pn
                            channel
                            state
                            evisc-tuple
                            (1-f clk)))))
                    (otherwise (mv (er-hard-val 0
                          'fmt0
                          "~@0"
                          (illegal-fmt-msg unrecognized-tilde-arg i s))
                        state)))))
              ((and (> col (fmt-soft-right-margin state)) (eql c #\ )) (pprogn (newline channel state)
                  (fmt0 s
                    alist
                    (scan-past-whitespace s (+f i 1) maximum)
                    maximum
                    0
                    pn
                    channel
                    state
                    evisc-tuple
                    (1-f clk))))
              ((and (>= col (fmt-soft-right-margin state)) (eql c #\-)) (pprogn (princ$ c channel state)
                  (newline channel state)
                  (fmt0 s
                    alist
                    (scan-past-whitespace s (+f i 1) maximum)
                    maximum
                    0
                    pn
                    channel
                    state
                    evisc-tuple
                    (1-f clk))))
              (t (maybe-newline (pprogn (princ$ c channel state)
                    (fmt0 s
                      alist
                      (+f i 1)
                      maximum
                      (if (eql c #\
)
                        0
                        (+f! col 1))
                      pn
                      channel
                      state
                      evisc-tuple
                      (1-f clk))))))))))))
tilde-*-&v-stringsfunction
(defun tilde-*-&v-strings
  (flg lst punct)
  (case flg
    (& (case punct
        (#\. (list "" ""~s*"." ""~s*" and " ""~s*", " lst))
        (#\, (list "" ""~s*"," ""~s*" and " ""~s*", " lst))
        (#\: (list "" ""~s*":" ""~s*" and " ""~s*", " lst))
        (#\; (list "" ""~s*";" ""~s*" and " ""~s*", " lst))
        (#\! (list "" ""~s*"!" ""~s*" and " ""~s*", " lst))
        (#\) (list "" ""~s*")" ""~s*" and " ""~s*", " lst))
        (#\? (list "" ""~s*"?" ""~s*" and " ""~s*", " lst))
        (otherwise (list "" ""~s*"" ""~s*" and " ""~s*", " lst))))
    (otherwise (case punct
        (#\. (list "" ""~s*"." ""~s*" or " ""~s*", " lst))
        (#\, (list "" ""~s*"," ""~s*" or " ""~s*", " lst))
        (#\: (list "" ""~s*":" ""~s*" or " ""~s*", " lst))
        (#\; (list "" ""~s*";" ""~s*" or " ""~s*", " lst))
        (#\! (list "" ""~s*"!" ""~s*" or " ""~s*", " lst))
        (#\) (list "" ""~s*")" ""~s*" or " ""~s*", " lst))
        (#\? (list "" ""~s*"?" ""~s*" or " ""~s*", " lst))
        (otherwise (list "" ""~s*"" ""~s*" or " ""~s*", " lst))))))
fmt1function
(defun fmt1
  (str alist col channel state evisc-tuple)
  (declare (type (unsigned-byte 60) col)
    (type string str)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep evisc-tuple))))
  (the2s (unsigned-byte 60)
    (cond ((not (character-alistp alist)) (mv (prog2$ (er hard!
              'fmt0
              "The second argument of any of the FMT family of ~
                      functions must satisfy ~x0, but ~x1 does not."
              'character-alistp
              alist)
            col)
          state))
      (t (mv-let (col state)
          (fmt0 str
            alist
            0
            (min (length str) (fixnum-bound))
            col
            nil
            channel
            state
            evisc-tuple
            (fixnum-bound))
          (declare (type (unsigned-byte 60) col))
          (prog2$ (and (eq channel *standard-co*)
              (maybe-finish-output$ *standard-co* state))
            (mv col state)))))))
fmtfunction
(defun fmt
  (str alist channel state evisc-tuple)
  (declare (type string str)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep evisc-tuple))))
  (the2s (unsigned-byte 60)
    (pprogn (newline channel state)
      (fmt1 str alist 0 channel state evisc-tuple))))
fmsfunction
(defun fms
  (str alist channel state evisc-tuple)
  (declare (type string str)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep evisc-tuple))))
  (pprogn (newline channel state)
    (mv-let (col state)
      (fmt1 str alist 0 channel state evisc-tuple)
      (declare (ignore col))
      state)))
fmt1!function
(defun fmt1!
  (str alist col channel state evisc-tuple)
  (declare (type (unsigned-byte 60) col)
    (type string str)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep evisc-tuple))))
  (the2s (unsigned-byte 60)
    (mv-let (erp col state)
      (state-global-let* ((write-for-read t))
        (mv-let (col state)
          (fmt1 str alist col channel state evisc-tuple)
          (mv nil col state)))
      (declare (ignore erp))
      (mv col state))))
fmt!function
(defun fmt!
  (str alist channel state evisc-tuple)
  (declare (type string str)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep evisc-tuple))))
  (the2s (unsigned-byte 60)
    (mv-let (erp col state)
      (state-global-let* ((write-for-read t))
        (mv-let (col state)
          (fmt str alist channel state evisc-tuple)
          (mv nil col state)))
      (declare (ignore erp))
      (mv col state))))
fms!function
(defun fms!
  (str alist channel state evisc-tuple)
  (declare (type string str)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep evisc-tuple))))
  (mv-let (erp val state)
    (state-global-let* ((write-for-read t))
      (pprogn (fms str alist channel state evisc-tuple)
        (mv nil nil state)))
    (declare (ignore erp val))
    state))
fmxmacro
(defmacro fmx
  (str &rest args)
  (declare (xargs :guard (<= (length args) 10)))
  `(fmt1 ,STR
    ,(MAKE-FMT-BINDINGS '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) ARGS)
    0
    *standard-co*
    state
    nil))
fmx-cw-msg-1-bodymacro
(defmacro fmx-cw-msg-1-body
  nil
  '(cond ((zp clk) (msg "Stack depth exceeded for guard check!"))
    ((or (not (mbt (natp i)))
       (not (mbt (natp maximum)))
       (>= i maximum)) nil)
    (t (let ((c0 (the character (charf s i))) (i+1 (1+f i))
          (clk-1 (1-f clk)))
        (declare (type character c0)
          (type (unsigned-byte 60) i+1 clk-1))
        (cond ((eql c0 #\~) (cond ((not (< i+1 maximum)) (illegal-fmt-msg tilde-arg-points-past-string i 1 maximum s))
              (t (let ((c1 (the character (charf s i+1))))
                  (declare (type character c1))
                  (case c1
                    ((#\  #\
 #\| #\% #\~ #\-) nil)
                    (otherwise (let ((i+2 (+f i 2)))
                        (declare (type (unsigned-byte 60) i+2))
                        (cond ((not (< i+2 maximum)) (illegal-fmt-msg tilde-arg-points-past-string i 2 maximum s))
                          (t (let* ((c2 (the character (charf s i+2))) (pair2 (assoc c2 alist))
                                (val2 (cdr pair2))
                                (i+3 (+f i 3)))
                              (declare (type character c2)
                                (type (unsigned-byte 60) i+3))
                              (cond ((not pair2) (illegal-fmt-msg unbound-tilde-arg i c2 alist s))
                                (t (case c1
                                    ((#\p #\q #\x #\y) (fmx-cw-msg-1 s alist i+3 maximum clk-1))
                                    ((#\P #\Q #\X #\Y) (cond ((not (< i+3 maximum)) (illegal-fmt-msg tilde-arg-points-past-string i 3 maximum s))
                                        (t (let* ((c3 (the character (charf s i+3))) (pair3 (assoc c3 alist))
                                              (val3 (cdr pair3)))
                                            (declare (type character c3))
                                            (cond ((not pair3) (illegal-fmt-msg unbound-tilde-arg i c3 alist s))
                                              ((not (standard-evisc-tuplep val3)) (illegal-fmt-msg bad-evisc-tuple
                                                  i
                                                  c3
                                                  val3
                                                  'standard-evisc-tuplep
                                                  s))
                                              (t (fmx-cw-msg-1 s alist (+f i 4) maximum clk-1)))))))
                                    (#\@ (or (cond ((and (stringp val2) (< (length val2) (fixnum-bound))) (fmx-cw-msg-1 val2 alist 0 (length val2) clk-1))
                                          ((and (consp val2)
                                             (msgp val2)
                                             (< (length (car val2)) (fixnum-bound))) (fmx-cw-msg-1 (car val2)
                                              (append (cdr val2) alist)
                                              0
                                              (length (car val2))
                                              clk-1))
                                          (t (illegal-fmt-msg bad-tilde-@-arg i val2 'character-alistp s)))
                                        (fmx-cw-msg-1 s alist i+3 maximum clk-1)))
                                    (#\# (cond ((not (< i+3 maximum)) (illegal-fmt-msg tilde-arg-points-past-string i 3 maximum s))
                                        (t (let ((i+4 (+f i 4)))
                                            (declare (type (unsigned-byte 60) i+4))
                                            (cond ((not (< i+4 maximum)) (illegal-fmt-msg tilde-arg-points-past-string i 4 maximum s))
                                              (t (let ((n (find-alternative-start c2 s i maximum t)) (max+1 (1+f maximum)))
                                                  (declare (type (signed-byte 61) n max+1))
                                                  (cond ((= n max+1) (illegal-fmt-msg find-alternative-start i s))
                                                    ((= n maximum) (illegal-fmt-msg find-alternative-skip s))
                                                    ((= n (-f maximum)) (illegal-fmt-msg find-alternative-start1-b s))
                                                    ((< n 0) (illegal-fmt-msg find-alternative-start1-a
                                                        "starting"
                                                        i
                                                        (zero-one-or-more (-f n))
                                                        (-f n)
                                                        s))
                                                    (t (let ((m (find-alternative-stop s n maximum t)))
                                                        (declare (type (unsigned-byte 60) m))
                                                        (cond ((eql m max+1) (illegal-fmt-msg find-alternative-stop s))
                                                          (t (let ((o (find-alternative-skip s m maximum t)))
                                                              (declare (type (unsigned-byte 60) o))
                                                              (cond ((= o 0) (illegal-fmt-msg find-alternative-skip s))
                                                                (t (or (fmx-cw-msg-1 s alist n m clk-1)
                                                                    (fmx-cw-msg-1 s alist o maximum clk-1)))))))))))))))))
                                    ((#\& #\v) (cond ((not (true-listp val2)) (illegal-fmt-msg bad-tilde-&v-arg
                                            i
                                            c2
                                            (if (eql c1 #\&)
                                              "~&"
                                              "~v")
                                            val2
                                            s))
                                        (t (fmx-cw-msg-1 s alist i+3 maximum clk-1))))
                                    (#\* (cond ((not (and (>= (len val2) 5)
                                             (character-alistp (cdr (cddddr val2))))) (illegal-fmt-msg bad-tilde-*-arg
                                            i
                                            c2
                                            'character-alistp
                                            val2
                                            s))
                                        (t (fmx-cw-msg-1 s alist i+3 maximum clk-1))))
                                    ((#\n #\N) (cond ((not (or (integerp val2)
                                             (and (consp val2) (integerp (car val2))))) (illegal-fmt-msg bad-tilde-n-arg
                                            i
                                            c2
                                            (if (eql c1 #\n)
                                              "~n"
                                              "~N")
                                            val2
                                            s))
                                        (t (fmx-cw-msg-1 s alist i+3 maximum clk-1))))
                                    (#\t (let ((goal-col val2))
                                        (cond ((not (natp goal-col)) (illegal-fmt-msg bad-tilde-t-arg-not-natp i c2 goal-col s))
                                          (nil (illegal-fmt-msg bad-tilde-t-arg-natp
                                              *fmt-hard-right-margin-default*
                                              (string c2)
                                              goal-col))
                                          (t (fmx-cw-msg-1 s alist i+3 maximum clk-1)))))
                                    (#\c (let ((pair val2))
                                        (cond ((and (consp pair)
                                             (integerp (car pair))
                                             (integerp (cdr pair))
                                             (>= (cdr pair) 0)) (fmx-cw-msg-1 s alist i+3 maximum clk-1))
                                          (t (illegal-fmt-msg bad-tilde-c-arg i pair s)))))
                                    ((#\f #\F) (fmx-cw-msg-1 s alist i+3 maximum clk-1))
                                    ((#\s #\S) (let ((x val2))
                                        (cond ((or (symbolp x) (stringp x) (acl2-numberp x)) (fmx-cw-msg-1 s alist i+3 maximum clk-1))
                                          (t (illegal-fmt-msg bad-tilde-s-arg
                                              (if (eql c1 #\s)
                                                "s"
                                                "S")
                                              i
                                              x
                                              s)))))
                                    (#\_ (cond ((and (natp c2) (<= c2 (floor (fixnum-bound) 2))) (fmx-cw-msg-1 s alist i+3 maximum clk-1))
                                        (t (illegal-fmt-msg bad-tilde-_-arg
                                            i
                                            c2
                                            (floor (fixnum-bound) 2)
                                            s))))
                                    ((#\
 #\| #\% #\~ #\-) (fmx-cw-msg-1 s alist i+2 maximum clk-1))
                                    (otherwise (illegal-fmt-msg unrecognized-tilde-arg i s)))))))))))))))
          (t (fmx-cw-msg-1 s alist i+1 maximum clk-1)))))))
fmx-cw-msg-1function
(defun fmx-cw-msg-1
  (s alist i maximum clk)
  (declare (type (unsigned-byte 60) i maximum clk)
    (type string s)
    (xargs :guard (and (character-alistp alist)
        (< (length s) (fixnum-bound))
        (<= maximum (length s)))
      :guard-hints (("Goal" :in-theory (disable nth)))
      :measure (nfix clk)))
  (fmx-cw-msg-1-body))
fmx-cw-msgfunction
(defun fmx-cw-msg
  (str alist)
  (declare (xargs :guard t))
  (cond ((not (stringp str)) (msg "Not a string:~|~x0" str))
    ((not (character-alistp alist)) (msg "Not a character-alistp:~|~x0" alist))
    (t (let ((len (length str)))
        (cond ((not (< len (fixnum-bound))) (msg "String is too long:~|~x0" str))
          (t (fmx-cw-msg-1 str alist 0 (length str) (fixnum-bound))))))))
fmx-cw-fn-guardfunction
(defun fmx-cw-fn-guard
  (str alist)
  (declare (xargs :guard t))
  (null (fmx-cw-msg str alist)))
fmx-cw-fnfunction
(defun fmx-cw-fn
  (str alist)
  (declare (xargs :guard (fmx-cw-fn-guard str alist)))
  (fmt-to-comment-window str alist 0 nil nil))
fmx!-cw-fnfunction
(defun fmx!-cw-fn
  (str alist)
  (declare (xargs :guard (fmx-cw-fn-guard str alist)))
  (fmt-to-comment-window! str alist 0 nil nil))
fmx-cwmacro
(defmacro fmx-cw
  (str &rest args)
  `(fmx-cw-fn ,STR
    (pairlis2 '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
      (list ,@ARGS))))
fmx!-cwmacro
(defmacro fmx!-cw
  (str &rest args)
  `(fmx!-cw-fn ,STR
    (pairlis2 '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
      (list ,@ARGS))))
fmt-doc-example1function
(defun fmt-doc-example1
  (lst i)
  (cond ((null lst) nil)
    (t (cons (cons "~c0 (~n1)~tc~y2~|"
          (list (cons #\0 (cons i 5))
            (cons #\1 (list i))
            (cons #\2 (car lst))))
        (fmt-doc-example1 (cdr lst) (1+ i))))))
fmt-doc-examplefunction
(defun fmt-doc-example
  (x state)
  (fmt "Here is a true list:  ~x0.  It has ~#1~[no elements~/a single ~
        element~/~n2 elements~], ~@3~%~%We could print each element in square ~
        brackets:~%(~*4).  And if we wished to itemize them into column 15 we ~
        could do it like this~%0123456789012345~%~*5End of example."
    (list (cons #\0 x)
      (cons #\1 (cond ((null x) 0) ((null (cdr x)) 1) (t 2)))
      (cons #\2 (length x))
      (cons #\3
        (cond ((< (length x) 3) "and so we can't print the third one!")
          (t (cons "the third of which is ~x0."
              (list (cons #\0 (caddr x)))))))
      (cons #\4
        (list "[empty]"
          "[the end: ~y*]"
          "[almost there: ~y*], "
          "[~y*], "
          x))
      (cons #\5
        (list* ""
          "~@*"
          "~@*"
          "~@*"
          (fmt-doc-example1 x 0)
          (list (cons #\c 15)))))
    *standard-co*
    state
    nil))
*see-doc-set-iprint*constant
(defconst *see-doc-set-iprint*
  "~|(See :DOC set-iprint to be able to see elided values in this message.)")
fmt-abbrev1function
(defun fmt-abbrev1
  (str alist col channel state suffix-msg)
  (declare (type string str)
    (type (unsigned-byte 60) col)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep (abbrev-evisc-tuple state)))))
  (the2s (unsigned-byte 60)
    (pprogn (f-put-global 'evisc-hitp-without-iprint nil state)
      (mv-let (col state)
        (fmt1 str
          alist
          col
          channel
          state
          (abbrev-evisc-tuple state))
        (fmt1 "~@0~@1"
          (list (cons #\0
              (cond ((f-get-global 'evisc-hitp-without-iprint state) (assert$? (not (iprint-enabledp state))
                    *see-doc-set-iprint*))
                (t "")))
            (cons #\1 suffix-msg))
          col
          channel
          state
          nil)))))
fmt-abbrevfunction
(defun fmt-abbrev
  (str alist col channel state suffix-msg)
  (declare (type string str)
    (type (unsigned-byte 60) col)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep (abbrev-evisc-tuple state)))))
  (mv-let (col state)
    (fmt-abbrev1 str alist col channel state suffix-msg)
    (declare (ignore col))
    state))
*fmt-ctx-spacers*constant
(defconst *fmt-ctx-spacers*
  '(defun mutual-recursion
    defuns
    defthm
    defaxiom
    defconst
    defstobj
    defabsstobj
    defpkg
    deflabel
    deftheory
    defchoose
    verify-guards
    verify-termination
    defmacro
    in-theory
    in-arithmetic-theory
    regenerate-tau-database
    push-untouchable
    remove-untouchable
    reset-prehistory
    disable-ubt
    set-body
    table
    encapsulate
    include-book))
fmt-ctxfunction
(defun fmt-ctx
  (ctx col channel state)
  (declare (type (unsigned-byte 60) col)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep (abbrev-evisc-tuple state)))))
  (the2s (unsigned-byte 60)
    (cond ((null ctx) (mv col state))
      ((symbolp ctx) (fmt1 "~x0" (list (cons #\0 ctx)) col channel state nil))
      ((and (consp ctx) (symbolp (car ctx))) (fmt1 "(~@0~x1 ~x2 ...)"
          (list (cons #\0
              (if (member-eq (car ctx) *fmt-ctx-spacers*)
                " "
                ""))
            (cons #\1 (car ctx))
            (cons #\2 (cdr ctx)))
          col
          channel
          state
          nil))
      (t (fmt-abbrev1 "~@0"
          (list (cons #\0 ctx))
          col
          channel
          state
          "")))))
fmt-in-ctxfunction
(defun fmt-in-ctx
  (ctx col channel state)
  (declare (type (unsigned-byte 60) col)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep (abbrev-evisc-tuple state)))))
  (the2s (unsigned-byte 60)
    (cond ((null ctx) (fmt1 ":  " nil col channel state nil))
      (t (mv-let (col state)
          (fmt1 " in " nil col channel state nil)
          (mv-let (col state)
            (fmt-ctx ctx col channel state)
            (fmt1 ":  " nil col channel state nil)))))))
er-off-p1function
(defun er-off-p1
  (summary wrld)
  (declare (xargs :guard (and (or (null summary) (stringp summary))
        (plist-worldp wrld)
        (string-alistp (table-alist 'inhibit-er-table wrld)))))
  (and summary
    (assoc-string-equal summary
      (table-alist 'inhibit-er-table wrld))))
er-off-pfunction
(defun er-off-p
  (summary state)
  (declare (xargs :stobjs state
      :guard (and (or (null summary) (stringp summary))
        (string-alistp (table-alist 'inhibit-er-table (w state))))))
  (er-off-p1 summary (w state)))
error-fms-channelfunction
(defun error-fms-channel
  (hardp ctx summary str alist channel state newlines)
  (declare (type string str)
    (type symbol channel)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (open-output-channel-p channel :character state)
        (standard-evisc-tuplep (abbrev-evisc-tuple state))
        (or (null summary) (stringp summary))
        (string-alistp (table-alist 'inhibit-er-table (w state))))))
  (cond ((er-off-p summary state) state)
    (t (flet ((newlines (n channel state)
           (case n
             (0 state)
             (1 (newline channel state))
             (2 (pprogn (newline channel state) (newline channel state)))
             (t (prog2$ (er hard?
                   'error-fms-channel
                   "Error: The NEWLINES argument of ~
                                            error-fms-channel must be 0, 1, ~
                                            or 2, hence ~x0 is illegal."
                   n)
                 state)))))
        (with-output-lock (pprogn (newlines newlines channel state)
            (mv-let (col state)
              (fmt1 (if hardp
                  "HARD ACL2 ERROR~#0~[~/ [~s1]~]"
                  "ACL2 Error~#0~[~/ [~s1]~]")
                (list (cons #\0
                    (if summary
                      1
                      0))
                  (cons #\1 summary))
                0
                channel
                state
                nil)
              (mv-let (col state)
                (fmt-in-ctx ctx col channel state)
                (fmt-abbrev str alist col channel state "")))
            (newlines newlines channel state)))))))
standard-cofunction
(defun standard-co
  (state)
  (declare (xargs :guard t))
  (f-get-global 'standard-co state))
error-fmsfunction
(defun error-fms
  (hardp ctx summary str alist state)
  (declare (type string str)
    (xargs :guard (and (fmt-state-p state)
        (character-alistp alist)
        (standard-evisc-tuplep (abbrev-evisc-tuple state))
        (or (null summary) (stringp summary))
        (string-alistp (table-alist 'inhibit-er-table (w state)))
        (symbolp (standard-co state))
        (open-output-channel-p (standard-co state) :character state))))
  (let ((chan (f-get-global 'standard-co state)))
    (error-fms-channel hardp ctx summary str alist chan state 2)))
push-warning-framefunction
(defun push-warning-frame (state) state)
absorb-framefunction
(defun absorb-frame
  (lst stk)
  (if (consp stk)
    (cons (union-equal lst (car stk)) (cdr stk))
    stk))
pop-warning-framefunction
(defun pop-warning-frame
  (accum-p state)
  (declare (ignore accum-p))
  (mv-let (erp val state)
    (read-acl2-oracle state)
    (declare (ignore erp))
    (mv val state)))
push-warningfunction
(defun push-warning
  (summary state)
  (declare (ignore summary))
  state)
record-maker-function-namefunction
(defun record-maker-function-name
  (name)
  (intern-in-package-of-symbol (coerce (append (coerce "Make " 'list)
        (coerce (symbol-name name) 'list)
        (coerce " record" 'list))
      'string)
    name))
record-changer-function-namefunction
(defun record-changer-function-name
  (name)
  (intern-in-package-of-symbol (coerce (append (coerce "Change " 'list)
        (coerce (symbol-name name) 'list)
        (coerce " record fields" 'list))
      'string)
    name))
makemacro
(defmacro make
  (&rest args)
  (cond ((keyword-value-listp (cdr args)) (cons (record-maker-function-name (car args)) (cdr args)))
    (t (er hard
        'record-error
        "Make was given a non-keyword as a field specifier.  ~
                The offending form is ~x0."
        (cons 'make args)))))
changemacro
(defmacro change
  (&rest args)
  (cond ((keyword-value-listp (cddr args)) (cons (record-changer-function-name (car args)) (cdr args)))
    (t (er hard
        'record-error
        "Change was given a non-keyword as a field specifier.  ~
                The offending form is ~x0."
        (cons 'change args)))))
make-record-car-cdrs1function
(defun make-record-car-cdrs1
  (lst var)
  (cond ((null lst) var)
    (t (list (car lst) (make-record-car-cdrs1 (cdr lst) var)))))
make-record-car-cdrsfunction
(defun make-record-car-cdrs
  (field-layout car-cdr-lst)
  (cond ((atom field-layout) (cond ((null field-layout) nil)
        (t (list (make-record-car-cdrs1 car-cdr-lst field-layout)))))
    (t (append (make-record-car-cdrs (car field-layout)
          (cons 'car car-cdr-lst))
        (make-record-car-cdrs (cdr field-layout)
          (cons 'cdr car-cdr-lst))))))
make-record-accessorsfunction
(defun make-record-accessors
  (name field-lst car-cdrs cheap)
  (cond ((null field-lst) nil)
    (t (cons (cond (cheap (list 'defabbrev
              (record-accessor-function-name name (car field-lst))
              (list (car field-lst))
              (car car-cdrs)))
          (t (list 'defabbrev
              (record-accessor-function-name name (car field-lst))
              (list (car field-lst))
              (sublis (list (cons 'name name)
                  (cons 'x (car field-lst))
                  (cons 'z (car car-cdrs)))
                '(prog2$ (or (and (consp x) (eq (car x) 'name))
                    (record-error 'name x))
                  z)))))
        (make-record-accessors name
          (cdr field-lst)
          (cdr car-cdrs)
          cheap)))))
symbol-name-tree-occurfunction
(defun symbol-name-tree-occur
  (sym sym-tree)
  (cond ((symbolp sym-tree) (cond ((equal (symbol-name sym) (symbol-name sym-tree)) sym-tree)
        (t nil)))
    ((atom sym-tree) nil)
    (t (or (symbol-name-tree-occur sym (car sym-tree))
        (symbol-name-tree-occur sym (cdr sym-tree))))))
some-symbol-name-tree-occurfunction
(defun some-symbol-name-tree-occur
  (syms sym-tree)
  (cond ((null syms) nil)
    ((symbol-name-tree-occur (car syms) sym-tree) t)
    (t (some-symbol-name-tree-occur (cdr syms) sym-tree))))
make-record-changer-consfunction
(defun make-record-changer-cons
  (fields field-layout x)
  (cond ((not (some-symbol-name-tree-occur fields field-layout)) x)
    ((atom field-layout) field-layout)
    (t (list 'cons
        (make-record-changer-cons fields
          (car field-layout)
          (list 'car x))
        (make-record-changer-cons fields
          (cdr field-layout)
          (list 'cdr x))))))
make-record-changer-let-bindingsfunction
(defun make-record-changer-let-bindings
  (field-layout lst)
  (cond ((null lst) nil)
    (t (let ((var (symbol-name-tree-occur (car lst) field-layout)))
        (cond ((null var) (er hard
              'record-error
              "A make or change form has used ~x0 as though ~
                         it were a legal field specifier in a record ~
                         with the layout ~x1."
              (car lst)
              field-layout))
          (t (cons (list var (cadr lst))
              (make-record-changer-let-bindings field-layout (cddr lst)))))))))
make-record-changer-letfunction
(defun make-record-changer-let
  (name field-layout cheap rec lst)
  (cond (cheap (list 'let
        (cons (list 'record-changer-not-to-be-used-elsewhere rec)
          (make-record-changer-let-bindings field-layout lst))
        (make-record-changer-cons (evens lst)
          field-layout
          'record-changer-not-to-be-used-elsewhere)))
    (t (list 'let
        (cons (list 'record-changer-not-to-be-used-elsewhere rec)
          (make-record-changer-let-bindings field-layout lst))
        (sublis (list (cons 'name name)
            (cons 'cons-nest
              (make-record-changer-cons (evens lst)
                field-layout
                '(cdr record-changer-not-to-be-used-elsewhere))))
          '(prog2$ (or (and (consp record-changer-not-to-be-used-elsewhere)
                (eq (car record-changer-not-to-be-used-elsewhere) 'name))
              (record-error 'name record-changer-not-to-be-used-elsewhere))
            (cons 'name cons-nest)))))))
make-record-changerfunction
(defun make-record-changer
  (name field-layout cheap)
  (list 'defmacro
    (record-changer-function-name name)
    '(&rest args)
    (list 'make-record-changer-let
      (kwote name)
      (kwote field-layout)
      cheap
      '(car args)
      '(cdr args))))
make-record-maker-consfunction
(defun make-record-maker-cons
  (fields field-layout)
  (cond ((atom field-layout) (cond ((some-symbol-name-tree-occur fields field-layout) field-layout)
        (t nil)))
    (t (list 'cons
        (make-record-maker-cons fields (car field-layout))
        (make-record-maker-cons fields (cdr field-layout))))))
make-record-maker-letfunction
(defun make-record-maker-let
  (name field-layout cheap lst)
  (cond (cheap (list 'let
        (make-record-changer-let-bindings field-layout lst)
        (make-record-maker-cons (evens lst) field-layout)))
    (t (list 'let
        (make-record-changer-let-bindings field-layout lst)
        (list 'cons
          (kwote name)
          (make-record-maker-cons (evens lst) field-layout))))))
make-record-makerfunction
(defun make-record-maker
  (name field-layout cheap)
  (list 'defmacro
    (record-maker-function-name name)
    '(&rest args)
    (list 'make-record-maker-let
      (kwote name)
      (kwote field-layout)
      cheap
      'args)))
make-record-field-lstfunction
(defun make-record-field-lst
  (field-layout)
  (cond ((atom field-layout) (cond ((null field-layout) nil) (t (list field-layout))))
    (t (append (make-record-field-lst (car field-layout))
        (make-record-field-lst (cdr field-layout))))))
record-maker-recognizer-namefunction
(defun record-maker-recognizer-name
  (name)
  (declare (xargs :guard (symbolp name)))
  (intern-in-package-of-symbol (concatenate 'string "WEAK-" (symbol-name name) "-P")
    name))
make-record-recognizer-bodyfunction
(defun make-record-recognizer-body
  (field-layout)
  (declare (xargs :guard t))
  (cond ((consp field-layout) (cond ((consp (car field-layout)) (cond ((consp (cdr field-layout)) `(and (consp x)
                (let ((x (car x)))
                  ,(MAKE-RECORD-RECOGNIZER-BODY (CAR FIELD-LAYOUT)))
                (let ((x (cdr x)))
                  ,(MAKE-RECORD-RECOGNIZER-BODY (CDR FIELD-LAYOUT)))))
            (t `(and (consp x)
                (let ((x (car x)))
                  ,(MAKE-RECORD-RECOGNIZER-BODY (CAR FIELD-LAYOUT)))))))
        ((consp (cdr field-layout)) `(and (consp x)
            (let ((x (cdr x)))
              ,(MAKE-RECORD-RECOGNIZER-BODY (CDR FIELD-LAYOUT)))))
        (t '(consp x))))
    (t t)))
make-record-recognizerfunction
(defun make-record-recognizer
  (name field-layout cheap recog-name)
  `(defun ,RECOG-NAME
    (x)
    (declare (xargs :mode :logic :guard t)
      ,@(AND CHEAP (SYMBOLP FIELD-LAYOUT) `((IGNORE X))))
    ,(COND (CHEAP (MAKE-RECORD-RECOGNIZER-BODY FIELD-LAYOUT))
       (T
        `(AND (CONSP X) (EQ (CAR X) ',NAME)
              ,@(AND (CONSP FIELD-LAYOUT)
                     `((LET ((X (CDR X)))
                         ,(MAKE-RECORD-RECOGNIZER-BODY FIELD-LAYOUT)))))))))
record-macrosfunction
(defun record-macros
  (name field-layout cheap recog-name)
  (declare (xargs :guard (or recog-name (symbolp name))))
  (let ((recog-name (or recog-name (record-maker-recognizer-name name))))
    (cons 'progn
      (append (make-record-accessors name
          (make-record-field-lst field-layout)
          (make-record-car-cdrs field-layout
            (if cheap
              nil
              '(cdr)))
          cheap)
        (list (make-record-changer name field-layout cheap)
          (make-record-maker name field-layout cheap)
          (make-record-recognizer name field-layout cheap recog-name))))))
defrecmacro
(defmacro defrec
  (name field-lst cheap &optional recog-name)
  (record-macros name field-lst cheap recog-name))
record-typemacro
(defmacro record-type (x) `(car ,X))
io?-nil-outputfunction
(defun io?-nil-output
  (lst default-bindings)
  (cond ((null lst) nil)
    (t (cons (cond ((eq (car lst) 'state) 'state)
          ((cadr (assoc-eq (car lst) default-bindings)))
          (t nil))
        (io?-nil-output (cdr lst) default-bindings)))))
check-exact-free-varsmacro
(defmacro check-exact-free-vars
  (ctx vars form)
  (declare (xargs :guard (symbol-listp vars)))
  `(translate-and-test (lambda (term)
      (let ((vars ',VARS) (all-vars (all-vars term)))
        (cond ((not (subsetp-eq all-vars vars)) (msg "Free vars problem with ~x0:  Variable~#1~[~/s~] ~&1 ~
                     occur~#1~[s~/~] in ~x2 even though not declared."
              ',CTX
              (reverse (set-difference-eq all-vars vars))
              term))
          ((not (subsetp-eq vars all-vars)) (msg "Free vars problem with ~x0: Variable~#1~[~/s~] ~&1 ~
                     ~#1~[does~/do~] not occur in ~x2 even though declared."
              ',CTX
              (reverse (set-difference-eq vars all-vars))
              term))
          (t t))))
    ,FORM))
formal-bindingsfunction
(defun formal-bindings
  (vars)
  (if (endp vars)
    nil
    (cons (list 'list
        (list 'quote (car vars))
        (list 'list ''quote (car vars)))
      (formal-bindings (cdr vars)))))
other
(defrec io-record (io-marker . form) t)
push-io-recordfunction
(defun push-io-record
  (io-marker form state)
  (declare (xargs :guard t))
  (f-put-global 'saved-output-reversed
    (cons (make io-record :io-marker io-marker :form form)
      (f-get-global 'saved-output-reversed state))
    state))
saved-output-token-pfunction
(defun saved-output-token-p
  (token state)
  (declare (xargs :stobjs state
      :guard (and (symbolp token)
        (or (eq (f-get-global 'saved-output-token-lst state) :all)
          (true-listp (f-get-global 'saved-output-token-lst state))))))
  (and (f-get-global 'saved-output-p state)
    (or (eq (f-get-global 'saved-output-token-lst state) :all)
      (member-eq token
        (f-get-global 'saved-output-token-lst state)))))
io?-wormhole-bindingsfunction
(defun io?-wormhole-bindings
  (i vars)
  (declare (xargs :guard (and (true-listp vars) (natp i))))
  (cond ((endp vars) nil)
    (t (cons (list (car vars) `(nth ,I (@ wormhole-input)))
        (io?-wormhole-bindings (1+ i) (cdr vars))))))
*tracked-warning-summaries*constant
(defconst *tracked-warning-summaries*
  '("rewrite-lambda-object"))
io?macro
(defmacro io?
  (token commentp
    shape
    vars
    body
    &key
    (clear 'nil clear-argp)
    (cursor-at-top 'nil cursor-at-top-argp)
    (pop-up 'nil pop-up-argp)
    (default-bindings 'nil)
    (chk-translatable 't)
    (io-marker 'nil))
  (declare (xargs :guard (and (symbolp token)
        (symbol-listp vars)
        (no-duplicatesp vars)
        (not (member-eq 'state vars))
        (assoc-eq token *window-descriptions*))))
  (let* ((associated-window (assoc-eq token *window-descriptions*)) (expansion `(let* ((io?-output-inhibitedp (member-eq ',TOKEN (f-get-global 'inhibit-output-lst state))) (io?-alist (and (not io?-output-inhibitedp)
                (list (cons #\w ,(CADR ASSOCIATED-WINDOW))
                  (cons #\c
                    ,(IF CLEAR-ARGP
     CLEAR
     (CADDR ASSOCIATED-WINDOW)))
                  (cons #\t
                    ,(IF CURSOR-AT-TOP-ARGP
     CURSOR-AT-TOP
     (CADDDR ASSOCIATED-WINDOW)))
                  (cons #\p
                    ,(IF POP-UP-ARGP
     POP-UP
     (CAR (CDDDDR ASSOCIATED-WINDOW))))
                  (cons #\k ,(SYMBOL-NAME TOKEN))))))
          (pprogn (if (or io?-output-inhibitedp
                (null (f-get-global 'window-interfacep state)))
              state
              (mv-let (io?-col state)
                (fmt1! (f-get-global 'window-interface-prelude state)
                  io?-alist
                  0
                  *standard-co*
                  state
                  nil)
                (declare (ignore io?-col))
                state))
            ,(LET ((BODY
        `(CHECK-VARS-NOT-FREE (IO?-OUTPUT-INHIBITEDP IO?-ALIST)
                              (CHECK-EXACT-FREE-VARS IO? (STATE ,@VARS)
                                                     ,BODY)))
       (NIL-OUTPUT
        (IF (EQ SHAPE 'STATE)
            'STATE
            (CONS 'MV (IO?-NIL-OUTPUT (CDR SHAPE) DEFAULT-BINDINGS))))
       (POSTLUDE
        `(MV-LET (IO?-COL STATE)
                 (IF (OR IO?-OUTPUT-INHIBITEDP
                         (NULL (F-GET-GLOBAL 'WINDOW-INTERFACEP STATE)))
                     (MV 0 STATE)
                     (FMT1! (F-GET-GLOBAL 'WINDOW-INTERFACE-POSTLUDE STATE)
                            IO?-ALIST 0 *STANDARD-CO* STATE NIL))
                 (DECLARE (IGNORE IO?-COL))
                 (CHECK-VARS-NOT-FREE (IO?-OUTPUT-INHIBITEDP IO?-ALIST IO?-COL)
                                      ,SHAPE))))
   (LET ((BODY
          (IF COMMENTP
              `(LET ,(IO?-WORMHOLE-BINDINGS 0 VARS)
                 ,BODY)
              BODY)))
     (COND
      ((EQ SHAPE 'STATE)
       `(PPROGN
         (IF IO?-OUTPUT-INHIBITEDP
             STATE
             ,BODY)
         ,POSTLUDE))
      (T
       `(MV-LET ,(CDR SHAPE)
                (IF IO?-OUTPUT-INHIBITEDP
                    ,NIL-OUTPUT
                    ,BODY)
                ,POSTLUDE)))))))))
    (cond (commentp (let ((form (cond ((eq shape 'state) `(pprogn ,EXPANSION (value :q)))
               (t `(mv-let ,(CDR SHAPE)
                   ,EXPANSION
                   (declare (ignore ,@(REMOVE1-EQ 'STATE (CDR SHAPE))))
                   (value :q))))))
          `(prog2$ ,(IF CHK-TRANSLATABLE
     `(CHK-TRANSLATABLE ,BODY ,SHAPE)
     NIL)
            (wormhole 'comment-window-io
              ',(COND
  ((OR (EQ TOKEN 'WARNING) (EQ TOKEN 'WARNING!))
   (ASSERT$ (EQUAL VARS '(SUMMARY CTX ALIST STR))
            '(LAMBDA (WHS)
               (COND
                ((AND SUMMARY
                      (MEMBER-STRING-EQUAL SUMMARY *TRACKED-WARNING-SUMMARIES*)
                      (STRING-ALISTP (WORMHOLE-DATA WHS)))
                 (LET ((EXPLN (LIST CTX ALIST STR))
                       (ENTRY
                        (OR (ASSOC-STRING-EQUAL SUMMARY (WORMHOLE-DATA WHS))
                            (CONS SUMMARY NIL))))
                   (COND
                    ((NOT (TRUE-LISTP (CDR ENTRY)))
                     (SET-WORMHOLE-ENTRY-CODE WHS :ENTER))
                    ((MEMBER-EQUAL EXPLN (CDR ENTRY))
                     (SET-WORMHOLE-ENTRY-CODE WHS :SKIP))
                    (T
                     (MAKE-WORMHOLE-STATUS WHS :ENTER
                                           (PUT-ASSOC-EQUAL (CAR ENTRY)
                                                            (CONS EXPLN
                                                                  (CDR ENTRY))
                                                            (WORMHOLE-DATA
                                                             WHS)))))))
                (T (SET-WORMHOLE-ENTRY-CODE WHS :ENTER))))))
  (T '(LAMBDA (WHS) (SET-WORMHOLE-ENTRY-CODE WHS :ENTER))))
              (list ,@VARS)
              ',FORM
              :ld-error-action :return! :ld-verbose nil
              :ld-pre-eval-print nil
              :ld-prompt nil))))
      (t `(pprogn (cond ((saved-output-token-p ',TOKEN state) (push-io-record ,IO-MARKER
                (list 'let (list ,@(FORMAL-BINDINGS VARS)) ',EXPANSION)
                state))
            (t state))
          ,EXPANSION)))))
io?-provemacro
(defmacro io?-prove
  (vars body &rest keyword-args)
  `(io? prove
    nil
    state
    ,VARS
    (if (gag-mode)
      state
      ,BODY)
    ,@KEYWORD-ARGS))
output-ignored-pfunction
(defun output-ignored-p
  (token state)
  (member-eq token (f-get-global 'inhibit-output-lst state)))
error1-state-pfunction
(defun error1-state-p
  (state)
  (declare (xargs :stobjs state))
  (and (fmt-state-p state)
    (let ((e (f-get-global 'abbrev-evisc-tuple state)))
      (or (eq e :default) (standard-evisc-tuplep e)))
    (string-alistp (table-alist 'inhibit-er-table (w state)))
    (symbolp (standard-co state))
    (open-output-channel-p (standard-co state) :character state)
    (open-output-channel-p *standard-co* :character state)
    (true-listp (f-get-global 'inhibit-output-lst state))
    (stringp (f-get-global 'window-interface-prelude state))
    (stringp (f-get-global 'window-interface-postlude state))
    (or (eq (f-get-global 'saved-output-token-lst state) :all)
      (true-listp (f-get-global 'saved-output-token-lst state)))))
state-p+function
(defun state-p+
  (state)
  (declare (xargs :stobjs state))
  (error1-state-p state))
error1function
(defun error1
  (ctx summary str alist state)
  (declare (type string str)
    (xargs :guard (and (error1-state-p state)
        (character-alistp alist)
        (or (null summary) (stringp summary)))))
  (pprogn (io? error
      nil
      state
      (alist str ctx summary)
      (error-fms nil ctx summary str alist state))
    (mv t nil state)))
error1-safefunction
(defun error1-safe
  (ctx str alist state)
  (declare (type string str)
    (xargs :guard (and (error1-state-p state) (character-alistp alist))))
  (pprogn (io? error
      nil
      state
      (alist str ctx)
      (error-fms nil ctx nil str alist state))
    (mv nil nil state)))
set-inhibited-summary-types-fnfunction
(defun set-inhibited-summary-types-fn
  (lst state)
  (declare (xargs :stobjs state :mode :program))
  (let ((msg (chk-inhibited-summary-types 'set-inhibited-summary-types
         lst)))
    (cond (msg (er soft 'set-inhibited-summary-types "~@0" msg))
      (t (pprogn (f-put-global 'inhibited-summary-types lst state)
          (value lst))))))
set-inhibited-summary-typesmacro
(defmacro set-inhibited-summary-types
  (lst)
  `(set-inhibited-summary-types-fn ,LST state))
*uninhibited-warning-summaries*constant
(defconst *uninhibited-warning-summaries*
  '("Uncertified" "Provisionally certified"
    "Skip-proofs"
    "Defaxioms"
    "Ttags"
    "Compiled file"
    "User-stobjs-modified"))
warning-off-p1function
(defun warning-off-p1
  (summary wrld ld-skip-proofsp)
  (declare (xargs :guard (and (or (null summary) (stringp summary))
        (plist-worldp wrld)
        (string-alistp (table-alist 'inhibit-warnings-table wrld)))))
  (or (and summary
      (assoc-string-equal summary
        (table-alist 'inhibit-warnings-table wrld)))
    (and (or (eq ld-skip-proofsp 'include-book)
        (eq ld-skip-proofsp 'include-book-with-locals)
        (eq ld-skip-proofsp 'initialize-acl2))
      (not (and summary
          (member-string-equal summary
            *uninhibited-warning-summaries*))))))
warning-off-pfunction
(defun warning-off-p
  (summary state)
  (warning-off-p1 summary (w state) (ld-skip-proofsp state)))
other
(defrec do-expressionp (stobjs-out . with-vars) nil)
other
(defrec state-vars
  (((binding-count . boot-strap-flg) (temp-touchable-vars . safe-mode) . guard-checking-on) (ld-skip-proofsp . temp-touchable-fns)
    (parallel-execution-enabled . in-macrolet-def)
    do-expressionp
    warnings-as-errors . inhibit-output-lst)
  nil)
*default-state-vars*constant
(defconst *default-state-vars*
  (make state-vars
    :guard-checking-on t
    :inhibit-output-lst '(proof-tree)
    :binding-count 0))
default-state-varsmacro
(defmacro default-state-vars
  (state-p &rest
    args
    &key
    (safe-mode 'nil safe-mode-p)
    (boot-strap-flg 'nil boot-strap-flg-p)
    (temp-touchable-vars 'nil temp-touchable-vars-p)
    (guard-checking-on 't guard-checking-on-p)
    (ld-skip-proofsp 'nil ld-skip-proofsp-p)
    (temp-touchable-fns 'nil temp-touchable-fns-p)
    (parallel-execution-enabled 'nil
      parallel-execution-enabled-p)
    (in-macrolet-def 'nil)
    (do-expressionp 'nil)
    (binding-count '0)
    (warnings-as-errors 'nil warnings-as-errors-p)
    (inhibit-output-lst ''(proof-tree) inhibit-output-lst-p))
  (cond ((eq state-p t) `(make state-vars
        :safe-mode ,(IF SAFE-MODE-P
     SAFE-MODE
     '(F-GET-GLOBAL 'SAFE-MODE STATE))
        :boot-strap-flg ,(IF BOOT-STRAP-FLG-P
     BOOT-STRAP-FLG
     '(F-GET-GLOBAL 'BOOT-STRAP-FLG STATE))
        :temp-touchable-vars ,(IF TEMP-TOUCHABLE-VARS-P
     TEMP-TOUCHABLE-VARS
     '(F-GET-GLOBAL 'TEMP-TOUCHABLE-VARS STATE))
        :guard-checking-on ,(IF GUARD-CHECKING-ON-P
     GUARD-CHECKING-ON
     '(F-GET-GLOBAL 'GUARD-CHECKING-ON STATE))
        :ld-skip-proofsp ,(IF LD-SKIP-PROOFSP-P
     LD-SKIP-PROOFSP
     '(F-GET-GLOBAL 'LD-SKIP-PROOFSP STATE))
        :temp-touchable-fns ,(IF TEMP-TOUCHABLE-FNS-P
     TEMP-TOUCHABLE-FNS
     '(F-GET-GLOBAL 'TEMP-TOUCHABLE-FNS STATE))
        :parallel-execution-enabled ,(IF PARALLEL-EXECUTION-ENABLED-P
     PARALLEL-EXECUTION-ENABLED
     '(F-GET-GLOBAL 'PARALLEL-EXECUTION-ENABLED STATE))
        :in-macrolet-def ,IN-MACROLET-DEF
        :do-expressionp ,DO-EXPRESSIONP
        :binding-count ,BINDING-COUNT
        :warnings-as-errors ,(IF WARNINGS-AS-ERRORS-P
     WARNINGS-AS-ERRORS
     '(F-GET-GLOBAL 'WARNINGS-AS-ERRORS STATE))
        :inhibit-output-lst ,(IF INHIBIT-OUTPUT-LST-P
     INHIBIT-OUTPUT-LST
     '(F-GET-GLOBAL 'INHIBIT-OUTPUT-LST STATE))))
    ((null args) '*default-state-vars*)
    (t `(make state-vars
        :safe-mode ,SAFE-MODE
        :boot-strap-flg ,BOOT-STRAP-FLG
        :temp-touchable-vars ,TEMP-TOUCHABLE-VARS
        :guard-checking-on ,GUARD-CHECKING-ON
        :ld-skip-proofsp ,LD-SKIP-PROOFSP
        :temp-touchable-fns ,TEMP-TOUCHABLE-FNS
        :parallel-execution-enabled ,PARALLEL-EXECUTION-ENABLED
        :binding-count ,BINDING-COUNT
        :warnings-as-errors ,WARNINGS-AS-ERRORS
        :inhibit-output-lst ,INHIBIT-OUTPUT-LST))))
other
(defrec warnings-as-errors (default . alist) nil)
warnings-as-errors-defaultother
(defabbrev warnings-as-errors-default
  (x)
  (and x (access warnings-as-errors x :default)))
warnings-as-errors-alistother
(defabbrev warnings-as-errors-alist
  (x)
  (and x (access warnings-as-errors x :alist)))
set-warnings-as-errors-alistfunction
(defun set-warnings-as-errors-alist
  (strings flg alist uninhibited-warning-summaries)
  (cond ((endp strings) alist)
    ((member-string-equal (car strings)
       uninhibited-warning-summaries) (er hard
        'set-warnings-as-errors
        "It is illegal to specify that warnings of type ~x0 are to be ~
              converted to errors, because ~x0 is a member (up to case) of ~x1"
        (car strings)
        '*uninhibited-warning-summaries*))
    (t (set-warnings-as-errors-alist (cdr strings)
        flg
        (let ((pair (assoc-string-equal (car strings) alist)))
          (cond ((and (consp pair) (eq (cdr pair) flg)) alist)
            ((null pair) (acons (car strings) flg alist))
            (t (acons (car strings)
                flg
                (remove1-assoc-string-equal (car strings) alist)))))
        uninhibited-warning-summaries))))
set-warnings-as-errorsfunction
(defun set-warnings-as-errors
  (flg strings state)
  (declare (xargs :guard (member-eq flg '(t nil :always))))
  (cond ((eq strings :all) (f-put-global 'warnings-as-errors
        (make warnings-as-errors :default flg :alist nil)
        state))
    ((string-listp strings) (let* ((old (f-get-global 'warnings-as-errors state)) (default (warnings-as-errors-default old))
          (alist (warnings-as-errors-alist old)))
        (cond ((and (eq flg default)
             (null (assoc-string-equal (car strings) alist))) state)
          (t (f-put-global 'warnings-as-errors
              (if old
                (change warnings-as-errors
                  old
                  :alist (set-warnings-as-errors-alist strings
                    flg
                    alist
                    *uninhibited-warning-summaries*))
                (make warnings-as-errors
                  :default nil
                  :alist (set-warnings-as-errors-alist strings
                    flg
                    alist
                    *uninhibited-warning-summaries*)))
              state)))))
    (t (prog2$ (er hard
          'set-warnings-as-errors
          "Illegal second argument of ~x0, ~x1: must be :ALL or a ~
                   list of strings."
          'set-warnings-as-errors
          strings)
        state))))
warning1-bodyfunction
(defun warning1-body
  (ctx summary str+ alist state)
  (let ((channel (f-get-global 'proofs-co state)))
    (pprogn (if summary
        (push-warning summary state)
        state)
      (cond ((f-get-global 'raw-warning-format state) (cond ((consp str+) (fms "~y0"
                (list (cons #\0
                    (list :warning summary (cons (list :ctx ctx) (cdr str+)))))
                channel
                state
                nil))
            (t (fms "(:WARNING ~x0~t1~y2)~%"
                (list (cons #\0 summary)
                  (cons #\1 10)
                  (cons #\2
                    (list (cons :ctx ctx)
                      (cons :fmt-string str+)
                      (cons :fmt-alist alist))))
                channel
                state
                nil))))
        (t (let ((str (cond ((consp str+) (assert$ (and (stringp (car str+)) (alistp (cdr str+)))
                     (car str+)))
                 (t str+))))
            (mv-let (col state)
              (fmt "ACL2 Warning~#0~[~/ [~s1]~]"
                (list (cons #\0
                    (if summary
                      1
                      0))
                  (cons #\1 summary))
                channel
                state
                nil)
              (mv-let (col state)
                (fmt-in-ctx ctx col channel state)
                (fmt-abbrev str alist col channel state "~%~%")))))))))
warnings-as-errors-val-guardfunction
(defun warnings-as-errors-val-guard
  (summary warnings-as-errors)
  (declare (xargs :guard t))
  (and (or (null summary) (stringp summary))
    (or (null warnings-as-errors)
      (and (weak-warnings-as-errors-p warnings-as-errors)
        (string-alistp (warnings-as-errors-alist warnings-as-errors))))))
warnings-as-errors-valfunction
(defun warnings-as-errors-val
  (summary warnings-as-errors)
  (declare (xargs :guard (warnings-as-errors-val-guard summary warnings-as-errors)))
  (let* ((pair (and summary
         (assoc-string-equal summary
           (warnings-as-errors-alist warnings-as-errors)))) (erp (if pair
          (cdr pair)
          (warnings-as-errors-default warnings-as-errors))))
    (if (booleanp erp)
      erp
      :always)))
warning1-formmacro
(defmacro warning1-form
  (commentp)
  (declare (xargs :guard (not (or (eq commentp 'warnings-as-errors-val)
          (eq commentp 'check-warning-off)
          (eq commentp 'summary)))))
  `(mv-let (check-warning-off summary)
    (cond ((consp summary) (mv nil (car summary)))
      (t (mv t summary)))
    (let ((warnings-as-errors-val ,(IF COMMENTP
     `(EC-CALL
       (WARNINGS-AS-ERRORS-VAL SUMMARY
                               (ACCESS STATE-VARS STATE-VARS
                                       :WARNINGS-AS-ERRORS)))
     `(WARNINGS-AS-ERRORS-VAL SUMMARY (F-GET-GLOBAL 'WARNINGS-AS-ERRORS STATE)))))
      (cond ((and (eq warnings-as-errors-val :always)
           (not (and summary
               (member-string-equal summary
                 *uninhibited-warning-summaries*)))) (let ((str (cond ((consp str) (car str)) (t str))))
            ,(COND
  (COMMENTP
   `(AND
     (NOT
      (EC-CALL
       (MEMBER-EQUAL 'ERROR
                     (ACCESS STATE-VARS STATE-VARS :INHIBIT-OUTPUT-LST))))
     (HARD-ERROR CTX (CONS SUMMARY STR) ALIST)))
  (T
   `(PROG2$
     (AND (NOT (MEMBER-EQ 'ERROR (F-GET-GLOBAL 'INHIBIT-OUTPUT-LST STATE)))
          (HARD-ERROR CTX (CONS SUMMARY STR) ALIST))
     STATE)))))
        ((and check-warning-off
           (not (and summary
               (member-string-equal summary
                 *uninhibited-warning-summaries*)))
           ,(IF COMMENTP
     '(OR
       (EC-CALL
        (MEMBER-EQUAL 'WARNING
                      (ACCESS STATE-VARS STATE-VARS :INHIBIT-OUTPUT-LST)))
       (WARNING-OFF-P1 SUMMARY WRLD
                       (ACCESS STATE-VARS STATE-VARS :LD-SKIP-PROOFSP)))
     '(OR (MEMBER-EQ 'WARNING (F-GET-GLOBAL 'INHIBIT-OUTPUT-LST STATE))
          (WARNING-OFF-P SUMMARY STATE)))) ,(IF COMMENTP
     NIL
     'STATE))
        ((and warnings-as-errors-val
           (not (and summary
               (member-string-equal summary
                 *uninhibited-warning-summaries*)))) (let ((str (cond ((consp str) (car str)) (t str))))
            ,(COND
  (COMMENTP
   `(AND
     (NOT
      (EC-CALL
       (MEMBER-EQUAL 'ERROR
                     (ACCESS STATE-VARS STATE-VARS :INHIBIT-OUTPUT-LST))))
     (HARD-ERROR CTX (CONS SUMMARY STR) ALIST)))
  (T
   `(PROG2$
     (AND (NOT (MEMBER-EQ 'ERROR (F-GET-GLOBAL 'INHIBIT-OUTPUT-LST STATE)))
          (HARD-ERROR CTX (CONS SUMMARY STR) ALIST))
     STATE)))))
        ((and summary
           (member-string-equal summary
             *uninhibited-warning-summaries*)) (io? warning!
            ,COMMENTP
            state
            (summary ctx alist str)
            (warning1-body ctx summary str alist state)
            :chk-translatable nil))
        (t (io? warning
            ,COMMENTP
            state
            (summary ctx alist str)
            (warning1-body ctx summary str alist state)
            :chk-translatable nil))))))
warning1function
(defun warning1
  (ctx summary str alist state)
  (warning1-form nil))
warning-disabled-pmacro
(defmacro warning-disabled-p
  (summary)
  (declare (xargs :guard (stringp summary)))
  (let ((tp (if (member-equal summary *uninhibited-warning-summaries*)
         'warning!
         'warning)))
    `(and (or (output-ignored-p ',TP state)
        (warning-off-p ,SUMMARY state))
      (not (eq (warnings-as-errors-val ,SUMMARY
            (f-get-global 'warnings-as-errors state))
          :always)))))
er-softmacro
(defmacro er-soft
  (context summary str &rest str-args)
  (let ((alist (make-fmt-bindings *base-10-chars* str-args)))
    (list 'error1 context summary str alist 'state)))
er-hard?macro
(defmacro er-hard?
  (context summary str &rest str-args)
  (let ((alist (make-fmt-bindings *base-10-chars* str-args)))
    (list 'hard-error context (list 'cons summary str) alist)))
er-hardmacro
(defmacro er-hard
  (context summary str &rest str-args)
  (let ((alist (make-fmt-bindings *base-10-chars* str-args)))
    (list 'illegal context (list 'cons summary str) alist)))
observation1-bodymacro
(defmacro observation1-body
  (commentp)
  `(io? observation
    ,COMMENTP
    state
    (str alist ctx abbrev-p)
    (let ((channel (f-get-global 'proofs-co state)))
      (mv-let (col state)
        (fmt "ACL2 Observation" nil channel state nil)
        (mv-let (col state)
          (fmt-in-ctx ctx col channel state)
          (cond (abbrev-p (fmt-abbrev str alist col channel state "~|"))
            ((null abbrev-p) (mv-let (col state)
                (fmt1 str alist col channel state nil)
                (declare (ignore col))
                (newline channel state)))
            (t (prog2$ (er hard
                  'observation1
                  "The abbrev-p (fourth) argument of ~
                                       observation1 must be t or nil, so the ~
                                       value ~x0 is illegal."
                  abbrev-p)
                state))))))
    :chk-translatable nil))
observation1function
(defun observation1
  (ctx str alist abbrev-p state)
  (observation1-body nil))
observation1-cwfunction
(defun observation1-cw
  (ctx str alist abbrev-p)
  (observation1-body t))
observationmacro
(defmacro observation
  (&rest args)
  `(cond ((or (eq (ld-skip-proofsp state) 'include-book)
       (eq (ld-skip-proofsp state) 'include-book-with-locals)
       (eq (ld-skip-proofsp state) 'initialize-acl2)) state)
    (t (observation1 ,(CAR ARGS)
        ,(CADR ARGS)
        ,(MAKE-FMT-BINDINGS '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) (CDDR ARGS))
        t
        state))))
observation-cwmacro
(defmacro observation-cw
  (&rest args)
  `(observation1-cw ,(CAR ARGS)
    ,(CADR ARGS)
    ,(MAKE-FMT-BINDINGS '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) (CDDR ARGS))
    t))
other
(defrec defstobj-field-template
  (((fieldp-name . type) init . length-name) (accessor-name . updater-name)
    (resize-name resizable . element-type) . other)
  nil)
other
(defrec defstobj-template
  ((congruent-to . non-memoizable) (recognizer . creator)
    field-templates
    inline . non-executable)
  nil)
packn1function
(defun packn1
  (lst)
  (declare (xargs :guard (atom-listp lst)))
  (cond ((endp lst) nil)
    (t (append (explode-atom (car lst) 10) (packn1 (cdr lst))))))
packn-posfunction
(defun packn-pos
  (lst witness)
  (declare (xargs :guard (and (atom-listp lst) (symbolp witness))))
  (intern-in-package-of-symbol (coerce (packn1 lst) 'string)
    witness))
find-first-non-cl-symbolfunction
(defun find-first-non-cl-symbol
  (lst)
  (declare (xargs :guard (atom-listp lst)))
  (cond ((endp lst) nil)
    ((and (symbolp (car lst))
       (not (equal (symbol-package-name (car lst)) "COMMON-LISP"))) (car lst))
    (t (find-first-non-cl-symbol (cdr lst)))))
packnfunction
(defun packn
  (lst)
  (declare (xargs :guard (atom-listp lst)))
  (packn-pos lst (or (find-first-non-cl-symbol lst) 'packn)))
pack2function
(defun pack2 (n1 n2) (packn (list n1 n2)))
defstobj-fnname-key2function
(defun defstobj-fnname-key2
  (type)
  (declare (xargs :guard t))
  (if (consp type)
    (case (car type)
      (array :array)
      (hash-table :hash-table)
      (stobj-table :stobj-table)
      (t :scalar))
    :scalar))
doublet-listpfunction
(defun doublet-listp
  (x)
  (declare (xargs :guard t))
  (cond ((atom x) (equal x nil))
    (t (and (true-listp (car x))
        (eql (length (car x)) 2)
        (doublet-listp (cdr x))))))
defstobj-fnnamefunction
(defun defstobj-fnname
  (root key1 key2 renaming-alist)
  (declare (xargs :guard (and (symbolp root)
        (member-eq key1
          '(:recognizer :length :resize :accessor :updater :creator :boundp :accessor? :remove :count :clear :init))
        (symbolp key2)
        (doublet-listp renaming-alist))))
  (let* ((default-fnname (case key1
         (:recognizer (packn-pos (list root "P") root))
         (:length (and (eq key2 :array)
             (packn-pos (list root "-LENGTH") root)))
         (:resize (and (eq key2 :array)
             (packn-pos (list "RESIZE-" root) root)))
         (:accessor (case key2
             (:array (packn-pos (list root "I") root))
             ((:hash-table :stobj-table) (packn-pos (list root "-GET") root))
             (otherwise root)))
         (:updater (case key2
             (:array (packn-pos (list "UPDATE-" root "I") root))
             ((:hash-table :stobj-table) (packn-pos (list root "-PUT") root))
             (otherwise (packn-pos (list "UPDATE-" root) root))))
         (:creator (packn-pos (list "CREATE-" root) root))
         (:boundp (and (or (eq key2 :hash-table) (eq key2 :stobj-table))
             (packn-pos (list root "-BOUNDP") root)))
         (:accessor? (and (eq key2 :hash-table)
             (packn-pos (list root "-GET?") root)))
         (:remove (and (or (eq key2 :hash-table) (eq key2 :stobj-table))
             (packn-pos (list root "-REM") root)))
         (:count (and (or (eq key2 :hash-table) (eq key2 :stobj-table))
             (packn-pos (list root "-COUNT") root)))
         (:clear (and (or (eq key2 :hash-table) (eq key2 :stobj-table))
             (packn-pos (list root "-CLEAR") root)))
         (:init (and (or (eq key2 :hash-table) (eq key2 :stobj-table))
             (packn-pos (list root "-INIT") root)))
         (otherwise (er hard
             'defstobj-fnname
             "Implementation error (bad case); please contact the ACL2 ~
                   implementors.")))) (temp (and default-fnname
          (assoc-eq default-fnname renaming-alist))))
    (if temp
      (cadr temp)
      default-fnname)))
defined-constantfunction
(defun defined-constant
  (name w)
  (and (symbolp name) (getpropc name 'const nil w)))
fix-stobj-array-typefunction
(defun fix-stobj-array-type
  (type wrld)
  (let* ((max (car (caddr type))) (n (cond ((consp wrld) (let ((qc (defined-constant max wrld)))
              (and qc (unquote qc))))
          (t (er hard
              'fix-stobj-array-type
              "Implementation error: Attempted to get logical result ~
                        for fix-stobj-array-type when the world is empty.")))))
    (cond (n (list (car type) (cadr type) (list n))) (t type))))
fix-stobj-hash-table-typefunction
(defun fix-stobj-hash-table-type
  (type wrld)
  (cond ((null (cddr type)) type)
    (t (let* ((size0 (caddr type)) (size (cond ((consp wrld) (let ((qc (defined-constant size0 wrld)))
                  (and qc (unquote qc))))
              (t (er hard
                  'fix-stobj-hash-table-type
                  "Implementation error: Attempted to get logical ~
                             result for fix-stobj-hash-table-type when the ~
                             world is empty.")))))
        (cond (size (list* (car type) (cadr type) size (cdddr type)))
          (t type))))))
fix-stobj-table-typefunction
(defun fix-stobj-table-type
  (type wrld)
  (cond ((null (cdr type)) type)
    (t (let* ((size0 (cadr type)) (size (cond ((consp wrld) (let ((qc (defined-constant size0 wrld)))
                  (and qc (unquote qc))))
              (t (er hard
                  'fix-stobj-hash-table-type
                  "Implementation error: Attempted to get logical ~
                             result for fix-stobj-table-type when the world ~
                             is empty.")))))
        (cond (size (list* (car type) size (cddr type))) (t type))))))
defstobj-field-templatesfunction
(defun defstobj-field-templates
  (field-descriptors renaming wrld)
  (cond ((endp field-descriptors) nil)
    (t (let* ((field-desc (car field-descriptors)) (field (if (atom field-desc)
              field-desc
              (car field-desc)))
          (type (if (consp field-desc)
              (or (cadr (assoc-keyword :type (cdr field-desc))) t)
              t))
          (element-type (if (consp field-desc)
              (cadr (assoc-keyword :element-type (cdr field-desc)))
              nil))
          (init (if (consp field-desc)
              (cadr (assoc-keyword :initially (cdr field-desc)))
              nil))
          (resizable (if (consp field-desc)
              (cadr (assoc-keyword :resizable (cdr field-desc)))
              nil))
          (key2 (defstobj-fnname-key2 type))
          (fieldp-name (defstobj-fnname field :recognizer key2 renaming))
          (accessor-name (defstobj-fnname field :accessor key2 renaming))
          (updater-name (defstobj-fnname field :updater key2 renaming))
          (boundp-name (defstobj-fnname field :boundp key2 renaming))
          (accessor?-name (defstobj-fnname field :accessor? key2 renaming))
          (remove-name (defstobj-fnname field :remove key2 renaming))
          (count-name (defstobj-fnname field :count key2 renaming))
          (clear-name (defstobj-fnname field :clear key2 renaming))
          (init-name (defstobj-fnname field :init key2 renaming))
          (resize-name (defstobj-fnname field :resize key2 renaming))
          (length-name (defstobj-fnname field :length key2 renaming)))
        (cons (make defstobj-field-template
            :fieldp-name fieldp-name
            :type (cond ((and (consp type) (eq (car type) 'array)) (fix-stobj-array-type type wrld))
              ((and (consp type) (eq (car type) 'hash-table)) (fix-stobj-hash-table-type type wrld))
              ((and (consp type) (eq (car type) 'stobj-table)) (fix-stobj-table-type type wrld))
              (t type))
            :init init
            :accessor-name accessor-name
            :updater-name updater-name
            :length-name length-name
            :resize-name resize-name
            :resizable resizable
            :element-type element-type
            :other (list boundp-name
              accessor?-name
              remove-name
              count-name
              clear-name
              init-name))
          (defstobj-field-templates (cdr field-descriptors)
            renaming
            wrld))))))
*defstobj-keywords*constant
(defconst *defstobj-keywords*
  '(:renaming :inline :congruent-to :non-memoizable :non-executable))
partition-rest-and-keyword-args1function
(defun partition-rest-and-keyword-args1
  (x)
  (declare (xargs :guard (true-listp x)))
  (cond ((endp x) (mv nil nil))
    ((keywordp (car x)) (mv nil x))
    (t (mv-let (rest keypart)
        (partition-rest-and-keyword-args1 (cdr x))
        (mv (cons (car x) rest) keypart)))))
partition-rest-and-keyword-args2function
(defun partition-rest-and-keyword-args2
  (keypart keys alist)
  (declare (xargs :guard (and (true-listp keypart) (true-listp keys) (alistp alist))))
  (cond ((endp keypart) alist)
    ((and (keywordp (car keypart))
       (consp (cdr keypart))
       (not (assoc-eq (car keypart) alist))
       (member (car keypart) keys)) (partition-rest-and-keyword-args2 (cddr keypart)
        keys
        (cons (cons (car keypart) (cadr keypart)) alist)))
    (t t)))
partition-rest-and-keyword-argsfunction
(defun partition-rest-and-keyword-args
  (x keys)
  (declare (xargs :guard (and (true-listp x) (true-listp keys))))
  (mv-let (rest keypart)
    (partition-rest-and-keyword-args1 x)
    (let ((alist (partition-rest-and-keyword-args2 keypart keys nil)))
      (cond ((eq alist t) (mv t nil nil)) (t (mv nil rest alist))))))
defstobj-templatefunction
(defun defstobj-template
  (name args wrld)
  (mv-let (erp field-descriptors key-alist)
    (partition-rest-and-keyword-args args *defstobj-keywords*)
    (cond (erp (er hard
          'defstobj
          "The keyword arguments to the DEFSTOBJ event must appear ~
          after all field descriptors.  The allowed keyword ~
          arguments are ~&0, and these may not be duplicated.  Thus, ~
          ~x1 is ill-formed."
          *defstobj-keywords*
          (list* 'defstobj name args)))
      (t (let ((renaming (cdr (assoc-eq :renaming key-alist))) (inline (cdr (assoc-eq :inline key-alist)))
            (congruent-to (cdr (assoc-eq :congruent-to key-alist)))
            (non-memoizable (cdr (assoc-eq :non-memoizable key-alist)))
            (non-executable (cdr (assoc-eq :non-executable key-alist))))
          (make defstobj-template
            :recognizer (defstobj-fnname name :recognizer :top renaming)
            :creator (defstobj-fnname name :creator :top renaming)
            :field-templates (defstobj-field-templates field-descriptors renaming wrld)
            :non-memoizable non-memoizable
            :non-executable non-executable
            :inline inline
            :congruent-to congruent-to))))))
simple-array-typefunction
(defun simple-array-type
  (array-etype dimensions)
  (declare (ignore dimensions))
  (cond ((eq array-etype t) `(simple-vector *))
    ((eq array-etype '*) (er hard
        'simple-array-type
        "Implementation error: We had thought that * is an invalid type-spec! ~
         ~ Please contact the ACL2 implementors."))
    (t `(simple-array ,ARRAY-ETYPE (*)))))
absstobj-namefunction
(defun absstobj-name
  (name type)
  (declare (type symbol name type))
  (mv-let (prefix suffix)
    (case type
      (:a (mv nil "$A"))
      (:c (mv nil "$C"))
      (:creator (mv "CREATE-" nil))
      (:recognizer (mv nil "P"))
      (:recognizer-logic (mv nil "$AP"))
      (:recognizer-exec (mv nil "$CP"))
      (:corr-fn (mv nil "$CORR"))
      (:correspondence (mv nil "{CORRESPONDENCE}"))
      (:preserved (mv nil "{PRESERVED}"))
      (:guard-thm (mv nil "{GUARD-THM}"))
      (otherwise (mv (er hard 'absstobj-name "Unrecognized type, ~x0." type)
          nil)))
    (let* ((s (symbol-name name)) (s (if prefix
            (concatenate 'string prefix s)
            s))
        (s (if suffix
            (concatenate 'string s suffix)
            s)))
      (intern-in-package-of-symbol s name))))
other
(defrec defstobj-redundant-raw-lisp-discriminator-value
  ((event recognizer . creator) congruent-stobj-rep
    non-memoizable . non-executable)
  nil)
other
(defrec stobj-property
  ((recognizer . creator) names . live-var)
  nil)
get-stobj-creatorfunction
(defun get-stobj-creator
  (stobj wrld)
  (cond ((eq stobj 'state) 'state-p)
    ((not (symbolp stobj)) nil)
    (wrld (let ((prop (getpropc stobj 'stobj nil wrld)))
        (and prop (access stobj-property prop :creator))))
    (t (er hard
        'stobj-creator
        "Implementation error: The call ~x0 is illegal, because ~
              get-stobj-creator must not be called inside the ACL2 loop (as ~
              is the case here) with wrld = nil."
        `(get-stobj-creator ,STOBJ nil)))))
the$macro
(defmacro the$
  (type val)
  (cond ((eq type t) val) (t `(the ,TYPE ,VAL))))
get-stobj-scalar-fieldmacro
(defmacro get-stobj-scalar-field
  (elt-type fld)
  `(the ,ELT-TYPE ,FLD))
make-stobj-scalar-fieldmacro
(defmacro make-stobj-scalar-field
  (elt-type init)
  `(the ,ELT-TYPE ,INIT))
maybe-contained-in-charactermutual-recursion
(mutual-recursion (defun maybe-contained-in-character
    (type)
    (cond ((atom type) (or (eq type 'character)
          (eq type 'standard-char)
          (eq type 'nil)))
      ((eq (car type) 'and) (some-maybe-contained-in-character (cdr type)))
      ((eq (car type) 'member) (character-listp (cdr type)))
      ((eq (car type) 'not) (consp (cadr type)))
      ((eq (car type) 'satisfies) t)
      ((eq (car type) 'or) (all-maybe-contained-in-character (cdr type)))
      (t nil)))
  (defun some-maybe-contained-in-character
    (lst)
    (cond ((endp lst) nil)
      (t (or (maybe-contained-in-character (car lst))
          (some-maybe-contained-in-character (cdr lst))))))
  (defun all-maybe-contained-in-character
    (lst)
    (cond ((endp lst) t)
      (t (and (maybe-contained-in-character (car lst))
          (all-maybe-contained-in-character (cdr lst)))))))
single-field-type-pfunction
(defun single-field-type-p
  (type)
  (and (consp type)
    (cond ((eq (car type) 'array) (not (maybe-contained-in-character (cadr type))))
      ((or (eq (car type) 'hash-table)
         (eq (car type) 'stobj-table)) t)
      (t nil))))
stobj-hash-table-testmacro
(defmacro stobj-hash-table-test (type) `(cadr ,TYPE))
stobj-hash-table-init-sizemacro
(defmacro stobj-hash-table-init-size (type) `(caddr ,TYPE))
stobj-hash-table-element-typemacro
(defmacro stobj-hash-table-element-type
  (type)
  `(or (cadddr ,TYPE) t))
defstobj-field-fns-raw-defsfunction
(defun defstobj-field-fns-raw-defs
  (var flush-var inline n field-templates)
  (cond ((endp field-templates) nil)
    (t (append (let* ((field-template (car field-templates)) (type (access defstobj-field-template field-template :type))
            (init (access defstobj-field-template field-template :init))
            (arrayp (and (consp type) (eq (car type) 'array)))
            (hashp (and (consp type) (eq (car type) 'hash-table)))
            (etype0 (cond (arrayp (cadr type))
                (hashp (stobj-hash-table-element-type type))
                (t nil)))
            (stobj-tablep (and (consp type) (eq (car type) 'stobj-table)))
            (hash-test (if hashp
                (stobj-hash-table-test type)
                (and stobj-tablep 'eq)))
            (single-fieldp (and (= n 0)
                (null (cdr field-templates))
                (single-field-type-p type)))
            (fld (if single-fieldp
                var
                `(svref ,VAR ,N)))
            (stobj-creator (get-stobj-creator (if (or arrayp hashp)
                  etype0
                  type)
                nil))
            (scalar-type (if stobj-creator
                t
                type))
            (array-etype (and arrayp
                (if stobj-creator
                  t
                  (or (access defstobj-field-template
                      field-template
                      :element-type)
                    etype0))))
            (simple-type (and arrayp (simple-array-type array-etype (caddr type))))
            (array-length (and arrayp (car (caddr type))))
            (vref (and arrayp
                (if (eq (car simple-type) 'simple-vector)
                  'svref
                  'aref)))
            (accessor-name (access defstobj-field-template
                field-template
                :accessor-name))
            (updater-name (access defstobj-field-template
                field-template
                :updater-name))
            (length-name (access defstobj-field-template field-template :length-name))
            (resize-name (access defstobj-field-template field-template :resize-name))
            (resizable (access defstobj-field-template field-template :resizable))
            (other (access defstobj-field-template field-template :other))
            (boundp-name (nth 0 other))
            (accessor?-name (nth 1 other))
            (remove-name (nth 2 other))
            (count-name (nth 3 other))
            (clear-name (nth 4 other))
            (init-name (nth 5 other)))
          (cond ((or hashp stobj-tablep) (let ((key (if stobj-tablep
                     '(current-stobj-gensym k)
                     (if (eq hash-test 'hons-equal)
                       '(hons-copy k)
                       'k))))
                `((,ACCESSOR-NAME ,@(COND
   ((AND HASHP (NULL INIT) (NOT STOBJ-CREATOR))
    `((K ,VAR) ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
      (VALUES (GETHASH ,KEY (THE HASH-TABLE ,FLD)))))
   (T
    `((K ,VAR ,@(AND STOBJ-TABLEP '(V)))
      ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
      (MULTIPLE-VALUE-BIND (VAL BOUNDP)
          (GETHASH ,KEY (THE HASH-TABLE ,FLD))
        (IF BOUNDP
            VAL
            ,(COND (STOBJ-CREATOR (ASSERT$ HASHP `(,STOBJ-CREATOR)))
                   (INIT
                    (ASSERT$ HASHP
                             (IF (EQ ETYPE0 'DOUBLE-FLOAT)
                                 (IF (EQL INIT 0)
                                     '(DF0)
                                     `(TO-DF ',INIT))
                                 `',INIT)))
                   (T (ASSERT$ STOBJ-TABLEP 'V))))))))) (,UPDATER-NAME (k v ,VAR)
                    ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                    (progn (memoize-flush ,VAR)
                      (setf (gethash ,KEY (the hash-table ,FLD)) v)
                      ,VAR))
                  (,BOUNDP-NAME (k ,VAR)
                    ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                    (multiple-value-bind (val boundp)
                      (gethash ,KEY (the hash-table ,FLD))
                      (declare (ignore val))
                      (if boundp
                        t
                        nil)))
                  ,@(AND HASHP
       `((,ACCESSOR?-NAME (K ,VAR) ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
          (MULTIPLE-VALUE-BIND (VAL BOUNDP)
              (GETHASH ,KEY (THE HASH-TABLE ,FLD))
            (IF BOUNDP
                (MV VAL T)
                (MV
                 ,(COND (STOBJ-CREATOR `(,STOBJ-CREATOR)) (INIT `',INIT)
                        (T NIL))
                 NIL))))))
                  (,REMOVE-NAME (k ,VAR)
                    ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                    (progn (remhash ,KEY (the hash-table ,FLD)) ,VAR))
                  (,COUNT-NAME (,VAR)
                    ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                    (progn ,@(AND STOBJ-TABLEP `((CLEAN-STOBJ-TABLE (THE HASH-TABLE ,FLD))))
                      (hash-table-count (the hash-table ,FLD))))
                  (,CLEAR-NAME (,VAR)
                    (progn (clrhash (the hash-table ,FLD))
                      ,@(AND (NOT SINGLE-FIELDP) (LIST VAR))))
                  (,INIT-NAME (ht-size rehash-size rehash-threshold ,VAR)
                    (progn (setf ,FLD
                        (make-hash-table-with-defaults ',HASH-TEST
                          ht-size
                          rehash-size
                          rehash-threshold))
                      ,@(AND (NOT SINGLE-FIELDP) (LIST VAR)))))))
            (arrayp `((,LENGTH-NAME (,VAR)
                 ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                 ,@(IF (NOT RESIZABLE)
      `((DECLARE (IGNORE ,VAR)) ,ARRAY-LENGTH)
      `((THE (AND FIXNUM (INTEGER 0 *)) (LENGTH ,FLD))))) (,RESIZE-NAME (i ,VAR)
                  ,@(IF (NOT RESIZABLE)
      `((DECLARE (IGNORE I))
        (PROG2$
         (ER HARD ',RESIZE-NAME
             "The array field corresponding to accessor ~x0 of ~
                          stobj ~x1 was not declared :resizable t.  ~
                          Therefore, it is illegal to resize this array."
             ',ACCESSOR-NAME ',VAR)
         ,VAR))
      `((IF (NOT (AND (INTEGERP I) (>= I 0) (< I ARRAY-DIMENSION-LIMIT)))
            (HARD-ERROR ',RESIZE-NAME
                        "Attempted array resize failed because the requested ~
                        size ~x0 was not a nonnegative integer less than the ~
                        value of Common Lisp constant array-dimension-limit, ~
                        which is ~x1.  These bounds on array sizes are fixed ~
                        by ACL2."
                        (LIST (CONS #\0 I) (CONS #\1 ARRAY-DIMENSION-LIMIT)))
            (LET* ((VAR ,VAR)
                   (OLD
                    ,(IF SINGLE-FIELDP
                         'VAR
                         `(SVREF VAR ,N)))
                   (MIN-INDEX (MIN I (LENGTH OLD)))
                   (NEW
                    (MAKE-ARRAY$ I :INITIAL-ELEMENT
                                 ,(IF (AND (EQ ETYPE0 'DOUBLE-FLOAT)
                                           (DFP INIT))
                                      `(TO-DF ,INIT)
                                      `',INIT)
                                 :ELEMENT-TYPE ',ARRAY-ETYPE)))
              (MEMOIZE-FLUSH ,FLUSH-VAR)
              (PROG1
                  (SETF ,(IF SINGLE-FIELDP
                             'VAR
                             `(SVREF VAR ,N))
                          (,(PACK2 'COPY-ARRAY- VREF) OLD NEW 0 MIN-INDEX))
                ,@(AND STOBJ-CREATOR
                       `((WHEN (< (LENGTH OLD) I)
                           (LOOP FOR J FROM (LENGTH OLD) TO (1- I)
                                 DO (SETF (SVREF NEW J) (,STOBJ-CREATOR)))))))
              ,@(AND (NOT SINGLE-FIELDP) '(VAR)))))))
                (,ACCESSOR-NAME (i ,VAR)
                  (declare (type (and fixnum (integer 0 *)) i))
                  ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                  (the$ ,ARRAY-ETYPE
                    ,(LET ((TYPE1 SIMPLE-TYPE))
   `(,VREF (THE ,TYPE1 ,FLD) (THE (AND FIXNUM (INTEGER 0 *)) I)))))
                (,UPDATER-NAME (i v ,VAR)
                  (declare (type (and fixnum (integer 0 *)) i)
                    ,@(AND (NOT (EQ ARRAY-ETYPE T)) `((TYPE ,ARRAY-ETYPE V))))
                  ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                  (progn (memoize-flush ,FLUSH-VAR)
                    (setf (,VREF ,(IF (EQ SIMPLE-TYPE T)
     FLD
     `(THE ,SIMPLE-TYPE ,FLD))
                        (the (and fixnum (integer 0 *)) i))
                      (the$ ,ARRAY-ETYPE v))
                    ,VAR))))
            ((eq scalar-type t) `((,ACCESSOR-NAME (,VAR)
                 ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                 ,FLD) (,UPDATER-NAME (v ,VAR)
                  ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                  (progn (memoize-flush ,FLUSH-VAR) (setf ,FLD v) ,VAR))))
            (t (assert$ (not stobj-creator)
                `((,ACCESSOR-NAME (,VAR)
                   ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                   (the$ ,SCALAR-TYPE
                     (get-stobj-scalar-field ,SCALAR-TYPE ,FLD))) (,UPDATER-NAME (v ,VAR)
                    ,@(AND (NOT (EQ SCALAR-TYPE T)) `((DECLARE (TYPE ,SCALAR-TYPE V))))
                    ,@(AND INLINE (LIST *STOBJ-INLINE-DECLARE*))
                    (progn (memoize-flush ,FLUSH-VAR)
                      (setf (get-stobj-scalar-field ,SCALAR-TYPE ,FLD)
                        (the$ ,SCALAR-TYPE v))
                      ,VAR)))))))
        (defstobj-field-fns-raw-defs var
          flush-var
          inline
          (1+ n)
          (cdr field-templates))))))
defstobj-raw-init-fieldsfunction
(defun defstobj-raw-init-fields
  (field-templates)
  (cond ((endp field-templates) nil)
    (t (let* ((field-template (car field-templates)) (type (access defstobj-field-template field-template :type))
          (arrayp (and (consp type) (eq (car type) 'array)))
          (hashp (and (consp type) (eq (car type) 'hash-table)))
          (stobj-tablep (and (consp type) (eq (car type) 'stobj-table)))
          (hash-test (if hashp
              (cadr type)
              (and stobj-tablep 'eq)))
          (hash-init-size (if hashp
              (stobj-hash-table-init-size type)
              (and stobj-tablep (cadr type))))
          (array-etype0 (and arrayp (cadr type)))
          (array-size (and arrayp (car (caddr type))))
          (stobj-creator (and (not hashp)
              (get-stobj-creator (if arrayp
                  array-etype0
                  type)
                nil)))
          (array-etype (and arrayp
              (if stobj-creator
                t
                (or (access defstobj-field-template
                    field-template
                    :element-type)
                  array-etype0))))
          (init (access defstobj-field-template field-template :init)))
        (cond (arrayp (cons (cond (stobj-creator (assert$ (null init)
                    (assert$ (natp array-size)
                      `(let ((ar (make-array$ ,ARRAY-SIZE :element-type ',ARRAY-ETYPE)))
                        (loop for
                          i
                          from
                          0
                          to
                          ,(1- ARRAY-SIZE)
                          do
                          (setf (svref ar i) (,STOBJ-CREATOR)))
                        ar))))
                ((and (eq array-etype0 'double-float) (dfp init)) `(make-array$ ,ARRAY-SIZE
                    :element-type ',ARRAY-ETYPE
                    :initial-element (to-df ,INIT)))
                (t `(make-array$ ,ARRAY-SIZE
                    :element-type ',ARRAY-ETYPE
                    :initial-element ',INIT)))
              (defstobj-raw-init-fields (cdr field-templates))))
          ((or hashp stobj-tablep) (cons `(make-hash-table-with-defaults ',HASH-TEST
                ,HASH-INIT-SIZE
                nil
                nil)
              (defstobj-raw-init-fields (cdr field-templates))))
          ((eq type t) (cons (kwote init)
              (defstobj-raw-init-fields (cdr field-templates))))
          (stobj-creator (cons `(,STOBJ-CREATOR)
              (defstobj-raw-init-fields (cdr field-templates))))
          ((and (eq type 'double-float) (dfp init)) (cons `(make-stobj-scalar-field ,TYPE (to-df ,INIT))
              (defstobj-raw-init-fields (cdr field-templates))))
          (t (cons `(make-stobj-scalar-field ,TYPE ',INIT)
              (defstobj-raw-init-fields (cdr field-templates)))))))))
defstobj-raw-init-setf-formsfunction
(defun defstobj-raw-init-setf-forms
  (var index raw-init-fields acc)
  (cond ((endp raw-init-fields) acc)
    (t (defstobj-raw-init-setf-forms var
        (1+ index)
        (cdr raw-init-fields)
        (cons `(setf (svref ,VAR ,INDEX) ,(CAR RAW-INIT-FIELDS))
          acc)))))
defstobj-raw-initfunction
(defun defstobj-raw-init
  (template)
  (let* ((field-templates (access defstobj-template template :field-templates)) (raw-init-fields (defstobj-raw-init-fields field-templates))
      (len (length field-templates))
      (single-fieldp (and (= len 1)
          (single-field-type-p (access defstobj-field-template (car field-templates) :type)))))
    (cond (single-fieldp `,(CAR RAW-INIT-FIELDS))
      (t `(cond ((< ,LEN call-arguments-limit) (vector ,@RAW-INIT-FIELDS))
          (t (let ((v (make-array$ ,LEN)))
              ,@(DEFSTOBJ-RAW-INIT-SETF-FORMS 'V 0 RAW-INIT-FIELDS NIL)
              v)))))))
defstobj-component-recognizer-callsfunction
(defun defstobj-component-recognizer-calls
  (field-templates n var ans)
  (cond ((endp field-templates) (reverse ans))
    (t (defstobj-component-recognizer-calls (cdr field-templates)
        (+ n 1)
        var
        (let* ((type (access defstobj-field-template (car field-templates) :type)) (nonresizable-ar (and (consp type)
                (eq (car type) 'array)
                (not (access defstobj-field-template
                    (car field-templates)
                    :resizable))))
            (pred-stmt `(,(ACCESS DEFSTOBJ-FIELD-TEMPLATE (CAR FIELD-TEMPLATES) :FIELDP-NAME) (nth ,N ,VAR))))
          (if nonresizable-ar
            (list* `(equal (len (nth ,N ,VAR)) ,(CAR (CADDR TYPE)))
              pred-stmt
              ans)
            (cons pred-stmt ans)))))))
stobjpfunction
(defun stobjp
  (x known-stobjs w)
  (declare (xargs :guard (and (plist-worldp w)
        (or (eq known-stobjs t) (true-listp known-stobjs)))))
  (and x
    (symbolp x)
    (if (eq known-stobjs t)
      (getpropc x 'stobj nil w)
      (member-eq x known-stobjs))))
translate-stobj-type-to-guardfunction
(defun translate-stobj-type-to-guard
  (x var wrld)
  (or (translate-declaration-to-guard x var wrld)
    (and (not (eq x 'state))
      (symbolp x)
      (let ((prop (getpropc x 'stobj nil wrld)))
        (and prop
          (list (access stobj-property prop :recognizer) var))))))
defstobj-component-recognizer-axiomatic-defsfunction
(defun defstobj-component-recognizer-axiomatic-defs
  (name template field-templates wrld)
  (cond ((endp field-templates) (let* ((recog-name (access defstobj-template template :recognizer)) (field-templates (access defstobj-template template :field-templates))
          (n (length field-templates)))
        (list `(,RECOG-NAME (,NAME)
            (declare (xargs :guard t :verify-guards t))
            (and (true-listp ,NAME)
              (= (length ,NAME) ,N)
              ,@(DEFSTOBJ-COMPONENT-RECOGNIZER-CALLS FIELD-TEMPLATES 0 NAME NIL)
              t)))))
    (t (let ((recog-name (access defstobj-field-template
             (car field-templates)
             :fieldp-name)) (type (access defstobj-field-template (car field-templates) :type)))
        (cons (cond ((and (consp type) (eq (car type) 'array)) (let ((etype (cadr type)))
                `(,RECOG-NAME (x)
                  (declare (xargs :guard t :verify-guards t))
                  (if (atom x)
                    (equal x nil)
                    (and ,(TRANSLATE-STOBJ-TYPE-TO-GUARD ETYPE '(CAR X) WRLD)
                      (,RECOG-NAME (cdr x)))))))
            ((and (consp type)
               (eq (car type) 'hash-table)
               (not (eq (stobj-hash-table-element-type type) t))) `(,RECOG-NAME (x)
                (declare (xargs :guard t :verify-guards t))
                (cond ((atom x) t)
                  ((consp (car x)) (and ,(TRANSLATE-STOBJ-TYPE-TO-GUARD (STOBJ-HASH-TABLE-ELEMENT-TYPE TYPE) '(CDAR X)
                                WRLD)
                      (,RECOG-NAME (cdr x))))
                  (t (,RECOG-NAME (cdr x))))))
            ((and (consp type)
               (or (eq (car type) 'hash-table)
                 (eq (car type) 'stobj-table))) `(,RECOG-NAME (x)
                (declare (xargs :guard t :verify-guards t)
                  (ignore x))
                t))
            (t (let ((type-term (translate-stobj-type-to-guard type 'x wrld)))
                `(,RECOG-NAME (x)
                  (declare (xargs :guard t :verify-guards t)
                    (ignorable x))
                  ,TYPE-TERM))))
          (defstobj-component-recognizer-axiomatic-defs name
            template
            (cdr field-templates)
            wrld))))))
congruent-stobj-repfunction
(defun congruent-stobj-rep
  (name wrld)
  (declare (xargs :guard (and (symbolp name) wrld (plist-worldp wrld))))
  (assert$ wrld
    (or (getpropc name 'congruent-stobj-rep nil wrld) name)))
all-but-lastfunction
(defun all-but-last
  (l)
  (declare (xargs :guard (true-listp l) :mode :logic))
  (cond ((endp l) nil)
    ((endp (cdr l)) nil)
    (t (cons (car l) (all-but-last (cdr l))))))
defstobj-raw-defsfunction
(defun defstobj-raw-defs
  (name template congruent-stobj-rep wrld)
  (let* ((recog (access defstobj-template template :recognizer)) (creator (access defstobj-template template :creator))
      (field-templates (access defstobj-template template :field-templates))
      (inline (access defstobj-template template :inline)))
    (append (all-but-last (defstobj-component-recognizer-axiomatic-defs name
          template
          field-templates
          wrld))
      `((,RECOG (,NAME)
         (cond ((live-stobjp ,NAME) t)
           (t (and (true-listp ,NAME)
               (= (length ,NAME) ,(LENGTH FIELD-TEMPLATES))
               ,@(DEFSTOBJ-COMPONENT-RECOGNIZER-CALLS FIELD-TEMPLATES 0 NAME NIL))))) (,CREATOR nil ,(DEFSTOBJ-RAW-INIT TEMPLATE))
        ,@(DEFSTOBJ-FIELD-FNS-RAW-DEFS NAME
                               (COND
                                ((ACCESS DEFSTOBJ-TEMPLATE TEMPLATE
                                         :NON-MEMOIZABLE)
                                 NIL)
                                (WRLD
                                 (LET ((CONGRUENT-TO
                                        (ACCESS DEFSTOBJ-TEMPLATE TEMPLATE
                                                :CONGRUENT-TO)))
                                   (IF CONGRUENT-TO
                                       (CONGRUENT-STOBJ-REP CONGRUENT-TO WRLD)
                                       NAME)))
                                (T CONGRUENT-STOBJ-REP))
                               INLINE 0 FIELD-TEMPLATES)))))
defconst-namefunction
(defun defconst-name
  (name)
  (intern-in-package-of-symbol (concatenate 'string "*" (symbol-name name) "*")
    name))
defstobj-defconstsfunction
(defun defstobj-defconsts
  (names index)
  (if (endp names)
    nil
    (cons `(defconst ,(DEFCONST-NAME (CAR NAMES)) ,INDEX)
      (defstobj-defconsts (cdr names) (1+ index)))))
strip-accessor-namesfunction
(defun strip-accessor-names
  (field-templates)
  (if (endp field-templates)
    nil
    (cons (access defstobj-field-template
        (car field-templates)
        :accessor-name)
      (strip-accessor-names (cdr field-templates)))))
the-live-varfunction
(defun the-live-var
  (name)
  (declare (xargs :guard (symbolp name)))
  (packn-pos (list "*THE-LIVE-" name "*") name))
other
(defrec ld-history-entry
  ((input error-flg) stobjs-out/value . user-data)
  nil)
parse-with-local-stobjfunction
(defun parse-with-local-stobj
  (x)
  (declare (xargs :guard t))
  (case-match x
    ((st ('mv-let . mv-let-body)) (cond ((symbolp st) (mv nil
            st
            (cons 'mv-let mv-let-body)
            (defstobj-fnname st :creator :top nil)))
        (t (mv t nil nil nil))))
    ((st ('mv-let . mv-let-body) creator) (mv nil st (cons 'mv-let mv-let-body) creator))
    (& (mv t nil nil nil))))
parse-versionfunction
(defun parse-version
  (version)
  (declare (xargs :guard (stringp version)))
  (let* ((root "ACL2 Version") (pos0 (if (and (stringp version)
            (<= 13 (length version))
            (equal (subseq version 0 12) root)
            (or (eql (char version 12) #\ ) (eql (char version 12) #\_)))
          13
          nil))
      (pos-lparen (position #\( version))
      (end0 (or pos-lparen (length version)))
      (rest (subseq version end0 (length version)))
      (from-pos0 (and pos0 (subseq version pos0 end0)))
      (pos1-from-pos0 (and pos0 (position #\. from-pos0)))
      (pos1 (and pos1-from-pos0 (+ pos0 pos1-from-pos0)))
      (major (and pos1
          (decimal-string-to-number (subseq version pos0 pos1)
            (- pos1 pos0)
            0)))
      (from-pos1 (and pos1 (subseq version (1+ pos1) end0)))
      (pos2-from-pos1 (and pos1 (position #\. from-pos1)))
      (pos2 (if pos2-from-pos1
          (+ (1+ pos1) pos2-from-pos1)
          (and pos1 end0)))
      (minor (and pos2
          (decimal-string-to-number (subseq version (1+ pos1) pos2)
            (1- (- pos2 pos1))
            0)))
      (incrl (if (and pos2 (< pos2 end0))
          (decimal-string-to-number (subseq version (1+ pos2) end0)
            (1- (- end0 pos2))
            0)
          0)))
    (mv major minor incrl rest)))
pcd2function
(defun pcd2
  (n channel state)
  (declare (xargs :guard (integerp n)))
  (cond ((< n 10) (pprogn (princ$ "0" channel state) (princ$ n channel state)))
    (t (princ$ n channel state))))
power-repfunction
(defun power-rep
  (n b)
  (if (< n b)
    (list n)
    (cons (rem n b) (power-rep (floor n b) b))))
decode-idatefunction
(defun decode-idate
  (n)
  (let ((tuple (power-rep n 100)))
    (cond ((< (len tuple) 6) (er hard
          'decode-idate
          "Idates are supposed to decode to a list of at least length six ~
           but ~x0 decoded to ~x1."
          n
          tuple))
      ((equal (len tuple) 6) tuple)
      (t (let ((secs (nth 0 tuple)) (mins (nth 1 tuple))
            (hrs (nth 2 tuple))
            (day (nth 3 tuple))
            (mo (nth 4 tuple))
            (yr (power-eval (cdr (cddddr tuple)) 100)))
          (list secs mins hrs day mo yr))))))
print-idatefunction
(defun print-idate
  (n channel state)
  (let* ((x (decode-idate n)) (sec (car x))
      (minimum (cadr x))
      (hrs (caddr x))
      (day (cadddr x))
      (mo (car (cddddr x)))
      (yr (cadr (cddddr x))))
    (pprogn (princ$ (nth (1- mo)
          '(|January| |February|
            |March|
            |April|
            |May|
            |June|
            |July|
            |August|
            |September|
            |October|
            |November|
            |December|))
        channel
        state)
      (princ$ #\  channel state)
      (princ$ day channel state)
      (princ$ "," channel state)
      (princ$ #\  channel state)
      (princ$ (+ 1900 yr) channel state)
      (princ$ "  " channel state)
      (pcd2 hrs channel state)
      (princ$ ":" channel state)
      (pcd2 minimum channel state)
      (princ$ ":" channel state)
      (pcd2 sec channel state)
      state)))
good-bye-fnfunction
(defun good-bye-fn
  (status)
  (declare (xargs :mode :logic :guard t))
  status)
good-byemacro
(defmacro good-bye
  (&optional (status '0))
  `(good-bye-fn ,STATUS))
exitmacro
(defmacro exit
  (&optional (status '0))
  `(good-bye-fn ,STATUS))
quitmacro
(defmacro quit
  (&optional (status '0))
  `(good-bye-fn ,STATUS))
expand-tilde-to-user-home-dirfunction
(defun expand-tilde-to-user-home-dir
  (str os ctx state)
  (cond ((or (equal str "~")
       (and (< 1 (length str))
         (eql (char str 0) #\~)
         (eql (char str 1) #\/))) (let ((user-home-dir (f-get-global 'user-home-dir state)))
        (cond (user-home-dir (concatenate 'string
              user-home-dir
              (subseq str 1 (length str))))
          (t (let ((certify-book-info (f-get-global 'certify-book-info state)))
              (prog2$ (and (or certify-book-info (not (eq os :mswindows)))
                  (er hard
                    ctx
                    "The use of ~~/ for the user home directory ~
                                 in filenames is not supported ~@0."
                    (if certify-book-info
                      "inside books being certified"
                      "for this host Common Lisp")))
                str))))))
    (t str)))
save-exec-fnfunction
(defun save-exec-fn
  (exec-filename extra-startup-string
    host-lisp-args
    toplevel-args
    inert-args
    return-from-lp
    init-forms)
  (declare (ignore exec-filename
      extra-startup-string
      host-lisp-args
      toplevel-args
      inert-args
      return-from-lp
      init-forms))
  nil)
save-execmacro
(defmacro save-exec
  (exec-filename extra-startup-string
    &key
    host-lisp-args
    toplevel-args
    inert-args
    return-from-lp
    init-forms)
  `(save-exec-fn ,EXEC-FILENAME
    ,EXTRA-STARTUP-STRING
    ,HOST-LISP-ARGS
    ,TOPLEVEL-ARGS
    ,INERT-ARGS
    ,RETURN-FROM-LP
    ,INIT-FORMS))
*slash-dot-dot*constant
(defconst *slash-dot-dot*
  (concatenate 'string *directory-separator-string* ".."))
*length-slash-dot-dot*constant
(defconst *length-slash-dot-dot* (length *slash-dot-dot*))
find-dot-dotfunction
(defun find-dot-dot
  (full-pathname i)
  (declare (xargs :guard (and (stringp full-pathname)
        (natp i)
        (<= i (length full-pathname)))
      :measure (nfix (- (length full-pathname) i))))
  (let ((pos (search *slash-dot-dot* full-pathname :start2 i)))
    (and pos
      (let ((pos+3 (+ pos *length-slash-dot-dot*)))
        (cond ((or (eql pos+3 (length full-pathname))
             (eql (char full-pathname pos+3) *directory-separator*)) pos)
          ((mbt (<= pos+3 (length full-pathname))) (find-dot-dot full-pathname pos+3)))))))
cancel-dot-dotsmutual-recursion
(mutual-recursion (defun cancel-dot-dots
    (full-pathname)
    (declare (xargs :guard (stringp full-pathname)
        :measure (* 2 (length full-pathname))))
    (let ((p (find-dot-dot full-pathname 0)))
      (cond ((and p
           (mbt (and (natp p)
               (stringp full-pathname)
               (< p (length full-pathname))))) (let ((new-p (merge-using-dot-dot (subseq full-pathname 0 p)
                 (subseq full-pathname (1+ p) (length full-pathname)))))
            (and (mbt (and (stringp new-p)
                  (< (length new-p) (length full-pathname))))
              (cancel-dot-dots new-p))))
        (t full-pathname))))
  (defun get-parent-directory
    (p0)
    (declare (xargs :guard (stringp p0) :measure (1+ (* 2 (length p0)))))
    (let* ((p (and (mbt (stringp p0)) (cancel-dot-dots p0))) (posn (search *directory-separator-string* p :from-end t)))
      (cond (posn (subseq p 0 posn))
        (t (er hard?
            'get-parent-directory
            "Implementation error!  Unable to get parent directory for ~
             directory ~x0."
            p0)))))
  (defun merge-using-dot-dot
    (p s)
    (declare (xargs :guard (and (stringp p) (stringp s) (not (equal s "")))
        :measure (+ 1 (* 2 (+ (length p) (length s))))))
    (cond ((not (mbt (and (stringp p) (stringp s) (not (equal s ""))))) nil)
      ((equal p "") s)
      ((equal s "..") (concatenate 'string
          (get-parent-directory p)
          *directory-separator-string*))
      ((equal s ".") (concatenate 'string p *directory-separator-string*))
      ((and (>= (length s) 3)
         (eql (char s 0) #\.)
         (eql (char s 1) #\.)
         (eql (char s 2) #\/)
         (mbt (<= (length (get-parent-directory p)) (length p)))) (merge-using-dot-dot (get-parent-directory p)
          (subseq s 3 (length s))))
      ((and (>= (length s) 2)
         (eql (char s 0) #\.)
         (eql (char s 1) #\/)) (merge-using-dot-dot p (subseq s 2 (length s))))
      (t (concatenate 'string p *directory-separator-string* s)))))
comment-string-p1function
(defun comment-string-p1
  (s i end)
  (declare (type (unsigned-byte 60) end)
    (xargs :measure (nfix (- end i))
      :guard (and (natp i) (stringp s) (= end (length s)) (<= i end))))
  (cond ((not (mbt (and (unsigned-byte-p *fixnat-bits* end)
           (natp i)
           (stringp s)
           (= end (length s))
           (<= i end)))) (er hard 'comment-string-p1 "Guard violation!"))
    (t (let ((j (scan-past-whitespace s i end)))
        (cond ((= j end) t)
          ((eql (char s i) #\;) (let ((p (search *newline-string* s :start2 j)))
              (or (null p) (comment-string-p1 s (1+ p) end))))
          (t nil))))))
comment-string-pfunction
(defun comment-string-p
  (s)
  (declare (xargs :guard t))
  (and (stringp s)
    (let ((len (length s)))
      (and (unsigned-byte-p *fixnat-bits* len)
        (comment-string-p1 s 0 len)))))
other
(defrec print-control (header . alist) nil)
*print-control-defaults*constant
(defconst *print-control-defaults*
  `((print-base ',(CDR (ASSOC-EQ 'PRINT-BASE *INITIAL-GLOBAL-TABLE*))
     set-print-base) (print-case ',(CDR (ASSOC-EQ 'PRINT-CASE *INITIAL-GLOBAL-TABLE*))
      set-print-case)
    (print-circle ',(CDR (ASSOC-EQ 'PRINT-CIRCLE *INITIAL-GLOBAL-TABLE*))
      set-print-circle)
    (print-escape ',(CDR (ASSOC-EQ 'PRINT-ESCAPE *INITIAL-GLOBAL-TABLE*))
      set-print-escape)
    (print-length ',(CDR (ASSOC-EQ 'PRINT-LENGTH *INITIAL-GLOBAL-TABLE*))
      set-print-length)
    (print-level ',(CDR (ASSOC-EQ 'PRINT-LEVEL *INITIAL-GLOBAL-TABLE*))
      set-print-level)
    (print-lines ',(CDR (ASSOC-EQ 'PRINT-LINES *INITIAL-GLOBAL-TABLE*))
      set-print-lines)
    (print-pretty ',(CDR (ASSOC-EQ 'PRINT-PRETTY *INITIAL-GLOBAL-TABLE*))
      set-print-pretty)
    (print-radix ',(CDR (ASSOC-EQ 'PRINT-RADIX *INITIAL-GLOBAL-TABLE*))
      set-print-radix)
    (print-readably ',(CDR (ASSOC-EQ 'PRINT-READABLY *INITIAL-GLOBAL-TABLE*))
      set-print-readably)
    (print-right-margin ',(CDR (ASSOC-EQ 'PRINT-RIGHT-MARGIN *INITIAL-GLOBAL-TABLE*))
      set-print-right-margin)))
print-control-alistpfunction
(defun print-control-alistp
  (alist)
  (declare (xargs :guard (alistp alist) :mode :logic))
  (cond ((endp alist) t)
    ((let ((key (caar alist)) (val (cdar alist)))
       (case key
         (*print-base* (print-base-p val))
         (*print-case* (member-eq val '(:upcase :downcase)))
         ((*print-length* *print-level*
            *print-lines*
            *print-right-margin*) (check-null-or-natp val key))
         ((*print-circle* *print-escape*
            *print-pretty*
            *print-radix*
            *print-readably*) t)
         (otherwise (hard-error 'print-control-p
             "The symbol ~x0 is not a legal print control variable."
             (list (cons #\0 key)))))) (print-control-alistp (cdr alist)))
    (t nil)))
*raw-print-vars-keys*constant
(defconst *raw-print-vars-keys*
  (strip-cars *raw-print-vars-alist*))
alist-keys-subsetpfunction
(defun alist-keys-subsetp
  (x keys)
  (declare (xargs :guard (and (alistp x) (symbol-listp keys))))
  (cond ((endp x) t)
    ((member-eq (caar x) keys) (alist-keys-subsetp (cdr x) keys))
    (t nil)))
print-control-pfunction
(defun print-control-p
  (x)
  (declare (xargs :guard t))
  (and (weak-print-control-p x)
    (or (null (access print-control x :header))
      (comment-string-p (access print-control x :header)))
    (alistp (access print-control x :alist))
    (alist-keys-subsetp (access print-control x :alist)
      *raw-print-vars-keys*)
    (print-control-alistp (access print-control x :alist))))
print-object$-fnfunction
(defun print-object$-fn
  (x control channel state-state)
  (declare (ignorable control)
    (xargs :guard (and (state-p1 state-state)
        (symbolp channel)
        (open-output-channel-p1 channel :object state-state))))
  (let ((entry (cdr (assoc-eq channel (open-output-channels state-state)))))
    (update-open-output-channels (add-pair channel
        (cons (car entry) (cons x (cdr entry)))
        (open-output-channels state-state))
      state-state)))
print-object$function
(defun print-object$
  (x channel state)
  (declare (xargs :guard (and (symbolp channel)
        (open-output-channel-p channel :object state))))
  (print-object$-fn x
    (get-serialize-character state)
    channel
    state))
print-object$-preserving-casefunction
(defun print-object$-preserving-case
  (x channel state)
  (declare (xargs :guard (and (eq (get-serialize-character state) nil)
        (symbolp channel)
        (open-output-channel-p channel :object state))))
  (print-object$ x channel state))
print-object$+macro
(defmacro print-object$+
  (x channel
    &rest
    args
    &key
    (header 'nil headerp)
    (serialize-character 'nil serialize-character-p)
    &allow-other-keys)
  (declare (xargs :guard (keyword-value-listp args)))
  (cond ((and serialize-character-p
       (not (eq serialize-character nil))
       (not (equal serialize-character ''nil))
       (cddr args)) (er hard
        'print-object$+
        "It is illegal for a call of ~x0 to specify a value for ~
         :SERIALIZE-CHARACTER other than ~x1 or ~x2 when at least one other ~
         keyword argument is supplied."
        'print-object$+
        nil
        ''nil))
    (t `(print-object$-fn ,X
        ,(IF (AND SERIALIZE-CHARACTER-P (NOT (EQ SERIALIZE-CHARACTER NIL))
          (NOT (EQUAL SERIALIZE-CHARACTER ''NIL)))
     SERIALIZE-CHARACTER
     `(MAKE PRINT-CONTROL :HEADER
            ,(IF HEADERP
                 HEADER
                 *NEWLINE-STRING*)
            :ALIST ,(PRINT-OBJECT$+-ALIST ARGS)))
        ,CHANNEL
        state))))
make-sysfilemacro
(defmacro make-sysfile (key str) `(cons ,KEY ,STR))
sysfile-pfunction
(defun sysfile-p
  (x)
  (declare (xargs :guard t))
  (and (consp x) (keywordp (car x)) (stringp (cdr x))))
sysfile-keyfunction
(defun sysfile-key
  (x)
  (declare (xargs :guard (sysfile-p x)))
  (car x))
sysfile-filenamefunction
(defun sysfile-filename
  (x)
  (declare (xargs :guard (sysfile-p x)))
  (cdr x))
project-dir-alistfunction
(defun project-dir-alist
  (wrld)
  (declare (xargs :guard (plist-worldp wrld)))
  (global-val 'project-dir-alist wrld))
project-dir-lookupfunction
(defun project-dir-lookup
  (key alist ctx)
  (declare (xargs :guard t))
  (let ((ans (cdr (hons-assoc-equal key alist))))
    (cond ((stringp ans) ans)
      ((null ctx) nil)
      (t (prog2$ (er-hard? ctx
            "Missing project"
            "The project-dir-alist needs an entry for the keyword ~
                         ~x0 but that keyword is missing the current ~
                         project-dir-alist, ~x1.  See :DOC project-dir-alist."
            key
            alist)
          *directory-separator-string*)))))
project-dirfunction
(defun project-dir
  (key wrld)
  (declare (xargs :guard (plist-worldp wrld)))
  (project-dir-lookup key
    (project-dir-alist wrld)
    'project-dir))
system-books-dirfunction
(defun system-books-dir
  (state)
  (declare (xargs :stobjs state))
  (project-dir :system (w state)))
string-prefixp-1function
(defun string-prefixp-1
  (str1 i str2)
  (declare (type string str1 str2)
    (type (unsigned-byte 60) i)
    (xargs :guard (and (<= i (length str1)) (<= i (length str2)))))
  (cond ((zpf i) t)
    (t (let ((i (1-f i)))
        (declare (type (unsigned-byte 60) i))
        (cond ((eql (the character (char str1 i))
             (the character (char str2 i))) (string-prefixp-1 str1 i str2))
          (t nil))))))
string-prefixpfunction
(defun string-prefixp
  (root string)
  (declare (type string root string)
    (xargs :guard (<= (length root) (fixnum-bound))))
  (let ((len (length root)))
    (and (<= len (length string))
      (assert$ (<= len (fixnum-bound))
        (string-prefixp-1 root len string)))))
project-dir-prefix-entryfunction
(defun project-dir-prefix-entry
  (filename project-dir-alist)
  (declare (xargs :guard (stringp filename)))
  (cond ((atom project-dir-alist) nil)
    ((and (consp (car project-dir-alist))
       (stringp (cdar project-dir-alist))
       (<= (length (cdar project-dir-alist)) (fixnum-bound))
       (string-prefixp (cdar project-dir-alist) filename)) (car project-dir-alist))
    (t (project-dir-prefix-entry filename (cdr project-dir-alist)))))
filename-to-book-name-1function
(defun filename-to-book-name-1
  (filename project-dir-alist)
  (declare (xargs :guard t))
  (let ((pair (and (stringp filename)
         (project-dir-prefix-entry filename project-dir-alist))))
    (cond (pair (make-sysfile (car pair)
          (subseq filename (length (cdr pair)) nil)))
      (t filename))))
filename-to-book-namefunction
(defun filename-to-book-name
  (filename wrld)
  (declare (xargs :guard (plist-worldp wrld)))
  (filename-to-book-name-1 filename (project-dir-alist wrld)))
our-merge-pathnamesfunction
(defun our-merge-pathnames
  (p s)
  (cond ((and (not (equal s ""))
       (eql (char s 0) *directory-separator*)) (er hard
        'our-merge-pathnames
        "Attempt to merge with an absolute filename, ~p0.  Please contact the ~
         ACL2 implementors."
        s))
    ((or (null p) (equal p "")) s)
    ((stringp p) (merge-using-dot-dot (if (eql (char p (1- (length p))) *directory-separator*)
          (subseq p 0 (1- (length p)))
          p)
        s))
    (t (er hard
        'our-merge-pathnames
        "The first argument of our-merge-pathnames must be a string, ~
         but the following is not:  ~p0."
        p))))
book-name-pfunction
(defun book-name-p
  (x)
  (declare (xargs :guard t))
  (or (stringp x) (sysfile-p x)))
book-name-listpfunction
(defun book-name-listp
  (x)
  (declare (xargs :guard t))
  (cond ((atom x) (null x))
    (t (and (book-name-p (car x)) (book-name-listp (cdr x))))))
book-name-to-filename-1function
(defun book-name-to-filename-1
  (x project-dir-alist ctx)
  (declare (xargs :guard (book-name-p x)))
  (cond ((consp x) (let ((dir (project-dir-lookup (sysfile-key x) project-dir-alist ctx)))
        (and (stringp dir)
          (concatenate 'string dir (sysfile-filename x)))))
    (t x)))
book-name-to-filenamefunction
(defun book-name-to-filename
  (x wrld ctx)
  (declare (xargs :guard (and (book-name-p x) (plist-worldp wrld))))
  (cond ((and (consp x)
       (absolute-pathname-string-p (sysfile-filename x)
         nil
         (os wrld))) (er hard?
        ctx
        "Implementation error the sysfile ~x0 has an absolute pathname as ~
             its sysfile-filename component."
        x))
    (t (book-name-to-filename-1 x (project-dir-alist wrld) ctx))))
book-name-lst-to-filename-lstfunction
(defun book-name-lst-to-filename-lst
  (x project-dir-alist ctx)
  (declare (xargs :guard (book-name-listp x)))
  (cond ((endp x) nil)
    (t (cons (book-name-to-filename-1 (car x) project-dir-alist ctx)
        (book-name-lst-to-filename-lst (cdr x)
          project-dir-alist
          ctx)))))
valid-book-name-pfunction
(defun valid-book-name-p
  (x os project-dir-alist)
  (or (stringp x)
    (and (sysfile-p x)
      (project-dir-lookup (sysfile-key x) project-dir-alist nil)
      (stringp (sysfile-filename x))
      (not (absolute-pathname-string-p (sysfile-filename x) nil os)))))
get-invalid-book-name-1function
(defun get-invalid-book-name-1
  (lst os project-dir-alist)
  (declare (xargs :guard (true-listp lst)))
  (cond ((endp lst) nil)
    ((valid-book-name-p (car lst) os project-dir-alist) (get-invalid-book-name-1 (cdr lst) os project-dir-alist))
    (t (car lst))))
get-invalid-book-namefunction
(defun get-invalid-book-name
  (lst os wrld)
  (declare (xargs :guard (and (true-listp lst) (plist-worldp wrld))))
  (get-invalid-book-name-1 lst os (project-dir-alist wrld)))
append-strip-carsfunction
(defun append-strip-cars
  (x y)
  (cond ((null x) y)
    (t (cons (car (car x)) (append-strip-cars (cdr x) y)))))
append-strip-cdrsfunction
(defun append-strip-cdrs
  (x y)
  (cond ((null x) y)
    (t (cons (cdr (car x)) (append-strip-cdrs (cdr x) y)))))
substring-pfunction
(defun substring-p
  (i1 s1 len i2 s2)
  (declare (type string s1 s2)
    (type (integer 0 *) i1 len i2)
    (xargs :guard (and (<= i1 len)
        (= len (length s1))
        (>= (- (length s2) i2) (- len i1)))
      :measure (nfix (- len i1))))
  (cond ((mbe :logic (not (and (natp i1) (natp len) (< i1 len)))
       :exec (= i1 len)) t)
    ((eql (the character (char s1 i1))
       (the character (char s2 i2))) (substring-p (1+ i1) s1 len (1+ i2) s2))
    (t nil)))
string-suffixpfunction
(defun string-suffixp
  (suffix string)
  (declare (type string suffix string))
  (let ((len-suffix (length suffix)) (len-string (length string)))
    (and (<= len-suffix len-string)
      (substring-p 0
        suffix
        len-suffix
        (- len-string len-suffix)
        string))))