;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; break$, trace$, trace!, break-on-error
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(trace$ (rewrite :entry (break$)))
:mini-proveall ; then :b in CCL, backtrace in SBCL
"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; cw, fmx-cw, fmx, and set-guard-msg
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(cw "~x0, ~x1~%" 'hello 'world) ; see :DOC fmt
(fmx-cw "~x0, ~x1~%" 'hello 'world) ; no change from cw
(fmx "~x0, ~x1~%" 'hello 'world) ; returns state
"But what if fmt arguments are missing?"
(cw "~x0, ~x1~%" 'hello) ; runtime error
(fmx-cw "~x0, ~x1~%" 'hello) ; guard violation
(fmx "~x0, ~x1~%" 'hello) ; runtime error
"Execute meta-x tags-search on: (set-guard-msg fmx-cw"
(trace$ fmx-cw-msg)
(fmx-cw "~x0, ~x1~%" 'hello) ; guard violation
"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ec-call and with-guard-checking
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun f1 (x)
  (declare (xargs :guard (consp x)))
  (car x))

(f1 3) ; guard violation

(defun f2 (x) ; guard verification fails:
  (declare (xargs :guard t))
  (f1 x))

(defun f2 (x) ; succeeds; see :DOC evaluation
  (declare (xargs :guard t))
  (ec-call (f1 x)))

(trace$ f1 f2)

(f2 3) ; guard violation

(defun f3 (x)
  (declare (xargs :guard t))
  (with-guard-checking nil (f2 x)))

(f3 3) ; logical value (car 3) = nil

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; measure-debug and guard-debug
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun foo (x y)
  (declare (xargs :measure-debug t))
  (if (or (consp x) (consp y))
      (1+ (foo (cdr x) (cdr y)))
    0))

(defun foo (x y)
  (declare (xargs :measure (+ (acl2-count x) (acl2-count y))))
  (if (or (consp x) (consp y))
      (1+ (foo (cdr x) (cdr y)))
    0))

(defun f (x)
  (declare (xargs :measure (f x)
                  :measure-debug t))
  (if (and (posp x)
           (< (f (1- x)) x))
      (f (f (1- x)))
    0))

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; oops, ubt, and ubu
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun f1 (x) x)
(defun f2 (x) x)
(defun f3 (x) x)
(defun f4 (x) x)
:pbt 0
:ubt f2
:pbt 0
:oops
:pbt 0
:ubu f2
:pbt 0

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; print-gv (from :DOC)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun foo (x)
  (declare (xargs :guard
                  (and (integerp x)
                       (posp (+ -2 x))
                       (posp (+ 3 x))
                       (posp (+ -4 x)))))
  x)
(foo -1)
:print-gv
"Evaluate the resulting FLET form, as is and with LIST replacing AND."
(print-gv :conjunct t)

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; printing-to-strings (essentially from :DOC)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(fmt-to-string "Big list: ~x0"
               (list (cons #\0 (make-list 30))))
(fmt-to-string "Big list: ~x0"
               (list (cons #\0 (make-list 30)))
               :fmt-control-alist
               '((fmt-soft-right-margin . 10000)
                 (fmt-hard-right-margin . 10000)))

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; redo-flat
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(encapsulate ()
  (defun f1 (x) x)
  (defun f2 (x) x)
  (defun f3 (x) Y) ; BUG!
  (defun f4 (x) x))
:pbt 0
:redo-flat
:pbt 0

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; set-iprint and without-evisc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun f () ; error
  (h t t t t t t t t t t t t))
(set-iprint t)
(defun f () ; error (again)
  (h t t t t t t t t t t t t))
'(H T T T T T T . #@1#)
(set-evisc-tuple  ; from :DOC
 (evisc-tuple 3   ; print-level
              4   ; print-length
              nil ; alist
              nil ; hiding-cars
              )
 :iprint :same ; better yet, T
 :sites :all)
'(H T T T T T T . #@1#)
(without-evisc '(H T T T T T T . #@1#))
(without-evisc '(H T T T T . #@3#))

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; set-raw-proof-format
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(set-raw-proof-format t)
(set-gag-mode nil)
(thm (equal (append (append x y) z) (append x y z)))
(set-raw-proof-format :clause)
(thm (equal (append (append x y) z) (append x y z)))

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; trans1, trans, trans*, and with-output
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(include-book "std/util/define" :dir :system)
:trans1 (define f (x) (cons x x)) ; Probably not very helpful
:trans (define f (x) (cons x x))  ; DEFINITELY not very helpful
:trans* t (define f (x) (cons x x)) ; Shows the generated defun, etc.
"Now use :trans* on the resulting defsection call (pasted in)."
"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; walkabout
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(walkabout (w state) state)
"Now walk about the world...."

1
pp
nx
pp
0
q

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; wet
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun f1 (x) (car x))
(defun f2 (x) (f1 x))
(defun f3 (x) (f2 x))
(f3 7)
(wet (f3 7))

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; with-brr-data (from :DOC)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(with-brr-data (thm (equal (append x y) (append y x))))
(cw-gstack-for-subterm (append y (cdr x)))

"[END OF DEMO]"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; End
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
