An example of the use of arrays in single-threaded objects
The following event
(defstobj ms (pcn :type integer :initially 0) (mem :type (array integer (100000)) :initially -1) (code :type t :initially nil))
introduces a single-threaded object named
The
You might expect the above
The above event defines the accessor function
In particular, the logical definitions of the two functions are:
(defun memi (i ms) (declare (xargs :guard (and (msp ms) (integerp i) (<= 0 i) (< i (mem-length ms))))) (nth i (nth 1 ms))) (defun update-memi (i v ms) (declare (xargs :guard (and (msp ms) (integerp i) (<= 0 i) (< i (mem-length ms)) (integerp v)))) (update-nth-array 1 i v ms))
For example, to access the 511th (0-based) memory location of the current
ACL2 !>(memi 511 ms) -1
The answer is
To set that element you could do
ACL2 !>(update-memi 511 777 ms) <ms> ACL2 !>(memi 511 ms) 777
The raw Lisp implementing these two functions is shown below.
(defun memi (i ms) (declare (type (and fixnum (integer 0 *)) i)) (the integer (aref (the (simple-array integer (*)) (svref ms 1)) (the (and fixnum (integer 0 *)) i)))) (defun update-memi (i v ms) (declare (type (and fixnum (integer 0 *)) i) (type integer v)) (progn (setf (aref (the (simple-array integer (*)) (svref ms 1)) (the (and fixnum (integer 0 *)) i)) (the integer v)) ms))
If you want to see the raw Lisp supporting a
To continue the stobj tour, see stobj-example-3.