Examples of
Below is a log of an ACL2 session demonstrating the behavior of a few
We'll describe the syntax and semantics of
In ACL2, These primitives may only be used within
We start the session with the following commands, whose output we do not
display here. Note that we use defstobj to introduce a
single-threaded object,
(include-book "projects/apply/top" :dir :system) (defstobj st fld1) (update-fld1 0 st) (defwarrant fld1) (defwarrant update-fld1)
So having set up our session, we now experiment with
; Reverse the elements of the initial value of temp. ACL2 !>(loop$ with temp = '(a b c) with ans = nil do (cond ((endp temp) (return ans)) (t (progn (setq ans (cons (car temp) ans)) (setq temp (cdr temp)))))) (C B A) ; Reverse the elements of lst down to the first xxx, or return ; not-found if there is no xxx in lst. ACL2 !>(defun reverse-to-xxx (lst) (loop$ with temp = lst with ans = nil do (cond ((endp temp) (return 'not-found)) (t (progn (cond ((eq (car temp) 'xxx) (loop-finish)) (t (setq ans (cons (car temp) ans)))) (setq temp (cdr temp))))) finally (return ans))) Since REVERSE-TO-XXX is non-recursive, its admission is trivial. We could deduce no constraints on the type of REVERSE-TO-XXX. Summary Form: ( DEFUN REVERSE-TO-XXX ...) Rules: NIL Time: 0.00 seconds (prove: 0.00, print: 0.00, other: 0.00) REVERSE-TO-XXX ACL2 !>(reverse-to-xxx '(a b c xxx d e f)) (C B A) ACL2 !>(reverse-to-xxx '(a b c d e f)) NOT-FOUND ; In the next example we will reverse the elements of the initial value of ; temp, except for the xxx's which we just drop but count. We use (fld1 st) ; to store the accumulated count. This loop$ returns the reversed elements ; and the final value of st. But first we'll show that (fld1 st) is ; initially 0. ACL2 !>(fld1 st) 0 ACL2 !>(loop$ with temp = '(a b c xxx d e xxx f g) with ans = nil do :values (nil st) (cond ((endp temp) (return (mv ans st))) (t (progn (cond ((eq (car temp) 'xxx) (setq st (update-fld1 (+ 1 (fld1 st)) st))) (t (setq ans (cons (car temp) ans)))) (setq temp (cdr temp)))))) ((G F E D C B A) <st>) ACL2 !>(fld1 st) 2
We included the last example showing that stobjs can be used inside of
See the ACL2 documentation topic DO-loop$ for a more thorough
discussion of
Now go to lp-section-14 (or return to the