• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • 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
        • Defpkg
        • Apply$
        • 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
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
        • Program-wrapper
        • Get-internal-time
        • Basics
          • Let
          • Return-last
          • Mv-let
          • Or
          • Flet
          • Mv
          • And
          • Booleanp
          • If
          • Not
          • Equal
          • Implies
          • Iff
          • Quote
          • Macrolet
          • Let*
          • Case-match
          • ACL2-count
          • Good-bye
          • Case
          • Cond
            • Null
            • Progn$
            • Identity
            • Xor
          • 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
    • Basics
    • ACL2-built-ins

    Cond

    Conditional based on if-then-else

    Cond is the construct for IF, THEN, ELSE IF, ... The test is against nil. The argument list for cond is a list of ``clauses'', each of which is a list. In ACL2, clauses must have length 1 or 2.

    ; Example 1.  The form
      (COND ((CONSP X) (FOO X Y))
            ((SYMBOLP X) (BAR X Y))
            (T (LIST X Y)))
    ; abbreviates the following.
      (IF (CONSP X)
          (FOO X Y)
          (IF (SYMBOLP X)
              (BAR X Y)
              (LIST X Y)))
    
    ; Example 2.  The form
      (COND ((CONSP X))
            ((SYMBOLP X) (BAR X Y)))
    ; abbreviates the following.
      (OR (CONSP X)
          (IF (SYMBOLP X) (BAR X Y) NIL))

    The results above were obtained by typing :trans1 followed by the form in the ACL2 loop, and then hitting <RETURN>. See trans1. You can experiment in this way to see other such examples.

    Cond is a Common Lisp macro. See any Common Lisp documentation for more information.

    Macro: cond

    (defmacro cond (&rest clauses)
              (declare (xargs :guard (cond-clausesp clauses)))
              (cond-macro clauses))

    Function: cond-macro

    (defun cond-macro (clauses)
           (declare (xargs :guard (cond-clausesp clauses)))
           (if (consp clauses)
               (if (and (eq (car (car clauses)) t)
                        (eq (cdr clauses) nil))
                   (if (cdr (car clauses))
                       (car (cdr (car clauses)))
                       (car (car clauses)))
                   (if (cdr (car clauses))
                       (list 'if
                             (car (car clauses))
                             (car (cdr (car clauses)))
                             (cond-macro (cdr clauses)))
                       (list 'or
                             (car (car clauses))
                             (cond-macro (cdr clauses)))))
               nil))