Locally bind state
This is an advanced topic, probably of interest only to system developers.
Consider the following example form:
(with-local-state (mv-let (result state) (compute-with-state x state) result))
This is equivalent to the following form.
(with-local-stobj state (mv-let (result state) (compute-with-state x state) result))
By default, this form is illegal, because ACL2 does not have a way to
unwind all changes to the ACL2 state; we say more on this issue below.
There may however be situations where you are willing to manage or overlook
this issue. In that case you may execute the following form to enable the use
of
(remove-untouchable create-state t)
Please be aware that no local state is actually created, however!
In particular, users of
Here is an example use of
(defttag t) (remove-untouchable create-state t) (set-state-ok t) (defun foo (state) (declare (xargs :mode :program)) (mv-let (channel state) (open-input-channel "my-file" :object state) (mv-let (eofp obj state) (read-object channel state) (declare (ignore eofp)) (let ((state (close-input-channel channel state))) (mv obj state))))) (defun bar () (declare (xargs :mode :program)) (with-local-state (mv-let (result state) (foo state) result))) ; Multiple-value return version: (defun foo2 (state) (declare (xargs :mode :program)) (mv-let (channel state) (open-input-channel "my-file" :object state) (mv-let (eofp obj state) (read-object channel state) (let ((state (close-input-channel channel state))) (mv eofp obj state))))) (defun bar2 () (declare (xargs :mode :program)) (with-local-state (mv-let (eofp result state) (foo2 state) (mv eofp result))))
Note for ACL2(p) users: When parallel-execution is enabled,
invocations of