• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
          • Member
          • Append
          • List
          • Nth
          • Len
          • True-listp
          • String-listp
          • Nat-listp
          • Character-listp
          • Symbol-listp
          • True-list-listp
          • Length
          • Search
          • Intersection$
          • Union$
          • Remove-duplicates
          • Position
          • Update-nth
          • Take
          • Nthcdr
          • Set-difference$
          • Subsetp
          • No-duplicatesp
          • Concatenate
          • Remove
          • Remove1
          • Intersectp
          • Endp
          • Keyword-value-listp
          • Integer-listp
          • Reverse
            • Nrev
              • Nrev-set-hint
              • Nrev-finish
                • Nrev-copy
                • Nrev-push
                • Nrev-fix
                • Nrev-demo
                • Nrev-stobj
                • Nrev2
                • Nrev-append
                • With-local-nrev
                • Nrev$c
              • Rev
              • Std/lists/reverse
              • Hons-reverse
            • Add-to-set
            • List-utilities
            • Set-size
            • Revappend
            • Subseq
            • Make-list
            • Last
            • Lists-light
            • Boolean-listp
            • Butlast
            • Pairlis$
            • Substitute
            • Count
            • Keyword-listp
            • List*
            • Eqlable-listp
            • Pos-listp
            • Integer-range-listp
            • Rational-listp
            • Evens
            • Atom-listp
            • ACL2-number-listp
            • Typed-list-utilities
            • Odds
            • List$
            • Listp
            • Standard-char-listp
            • Last-cdr
            • Pairlis
            • Proper-consp
            • Improper-consp
            • Pairlis-x2
            • Pairlis-x1
            • Merge-sort-lexorder
            • Fix-true-list
            • Real-listp
          • Invariant-risk
          • Errors
          • Defabbrev
          • Conses
          • Alists
          • Set-register-invariant-risk
          • Strings
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Nrev

    Nrev-finish

    Final step to extract the elements from an nrev.

    Signature: (nrev-finish nrev) → (mv list nrev')

    In the logic, this returns (list-fix nrev) as list, and also updates nrev' := nil.

    In the pure ACL2 implementation, this function is very much like nrev-copy. The underlying representation of nrev keeps the elements in reverse order, so nrev-finish has to reverse them, e.g., via reverse, which of course is O(n).

    In the optimized implementation, we have already constructed the list in reverse order, so we can simply return it, saving all that consing. For this to be sound, we must simultaneously clear out nrev—otherwise, a subsequent nrev-push would be destructively modifying conses that are visible elsewhere in the program.

    Definitions and Theorems

    Function: nrev$a-finish

    (defun nrev$a-finish (nrev$a)
      (declare (xargs :guard t))
      (let* ((elems (list-fix nrev$a)))
        (mv elems nil)))

    Function: nrev$c-finish

    (defun nrev$c-finish (nrev$c)
      (declare (xargs :stobjs nrev$c))
      (let* ((elems (reverse (nrev$c-acc nrev$c)))
             (nrev$c (update-nrev$c-acc nil nrev$c)))
        (mv elems nrev$c)))