• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Hons-and-memoization
      • Events
      • History
      • Parallelism
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Memoize
        • Mbe
        • Io
        • Apply$
        • Defpkg
        • Mutual-recursion
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Loop$-primer
        • Fast-alists
        • Defmacro
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Irrelevant-formals
        • Efficiency
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
          • Member
          • Append
          • Nth
            • Std/lists/nth
            • Nth-aliases-table
            • Equal-by-nths
            • First
            • Rest
            • Third
            • Tenth
            • Sixth
            • Seventh
            • Second
            • Ninth
            • Fourth
            • Fifth
            • Eighth
          • List
          • Len
          • True-listp
          • Symbol-listp
          • String-listp
          • Nat-listp
          • Character-listp
          • True-list-listp
          • Length
          • Search
          • Intersection$
          • Union$
          • Remove-duplicates
          • Position
          • Take
          • Update-nth
          • Set-difference$
          • Subsetp
          • No-duplicatesp
          • Concatenate
          • Remove
          • Nthcdr
          • Remove1
          • Intersectp
          • Endp
          • Keyword-value-listp
          • Reverse
          • List-utilities
          • Add-to-set
          • Set-size
          • Integer-listp
          • Revappend
          • Subseq
          • Make-list
          • Lists-light
          • Butlast
          • Pairlis$
          • Substitute
          • Count
          • Boolean-listp
          • List*
          • Keyword-listp
          • Eqlable-listp
          • Last
          • Integer-range-listp
          • Pos-listp
          • Rational-listp
          • Evens
          • Atom-listp
          • ACL2-number-listp
          • Good-atom-listp
          • Typed-list-utilities
          • Listp
          • Odds
          • 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
        • Defmacro-untouchable
        • Primitive
        • <<
        • Revert-world
        • Set-duplicate-keys-action
        • Unmemoize
        • Symbols
        • Def-list-constructor
        • Easy-simplify-term
        • Defiteration
        • Defopen
        • Sleep
      • Start-here
      • Real
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Testing-utilities
    • Math
  • Lists
  • ACL2-built-ins

Nth

The nth element (zero-based) of a list

(Nth n l) is the nth element of l, zero-based. If n is greater than or equal to the length of l, then nth returns nil.

(Nth n l) has a guard that n is a non-negative integer and l is a true-listp.

Nth is a Common Lisp function. See any Common Lisp documentation for more information.

Function: nth

(defun nth (n l)
       (declare (xargs :guard (and (integerp n)
                                   (>= n 0)
                                   (true-listp l))))
       (if (endp l)
           nil
           (if (zp n)
               (car l)
               (nth (- n 1) (cdr l)))))

Subtopics

Std/lists/nth
Lemmas about nth available in the std/lists library.
Nth-aliases-table
A table used to associate names for nth/update-nth printing
Equal-by-nths
Proof technique: show two lists are equal by showing that their nth elements are always the same.
First
First member of the list
Rest
Rest (cdr) of the list
Third
Third member of the list
Tenth
Tenth member of the list
Sixth
Sixth member of the list
Seventh
Seventh member of the list
Second
Second member of the list
Ninth
Ninth member of the list
Fourth
Fourth member of the list
Fifth
Fifth member of the list
Eighth
Eighth member of the list