• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
        • Deftreeops
        • Defdefparse
        • Defgrammar
        • Tree-utilities
        • Notation
          • Syntax-abstraction
          • Semantics
            • Tree-terminatedp
            • Tree->string
            • String-has-finite-parse-trees-p
            • Parse-trees-of-string-p
            • Tree-match-element-p
            • Parse-treep
            • Symbol
            • String-unambiguousp
            • Tree-match-num-val-p
            • Nat-match-insensitive-char-p
            • Nats-match-insensitive-chars-p
            • Tree-option
            • String-parsablep
            • Lookup-rulename
            • Nats-match-sensitive-chars-p
            • Numrep-match-repeat-range-p
            • Tree-match-char-val-p
            • Tree-list-match-repetition-p
            • String-ambiguousp
            • Parse
            • Tree-match-prose-val-p
            • Nat-match-sensitive-char-p
            • Theorems-about-terminated-trees-matching-elements
            • Tree-option-result
            • Tree-list-result
            • Tree-list-list-result
            • Tree-result
            • Tree-list-list-match-concatenation-p
            • Languagep
            • Terminal-string-for-rules-p
            • Tree-list-list-match-alternation-p
            • Tree-list-match-element-p
            • Parse!
            • String
            • Tree-set
            • Trees
              • Tree
                • Treep
                • Tree-case
                  • Tree-equiv
                  • Tree-nonleaf
                  • Tree-leafterm
                  • Tree-leafrule
                  • Tree-kind
                  • Tree-fix
                  • Tree-fix-when-nonleaf-norulename-nobranches
                  • Tree-count
                  • True-listp-of-car-of-tree-nonleaf->branches
                • Tree-list
                • Tree-list-list
            • Abstract-syntax
            • Core-rules
            • Concrete-syntax
          • Grammar-parser
          • Meta-circular-validation
          • Parsing-primitives-defresult
          • Parsing-primitives-seq
          • Operations
          • Examples
          • Differences-with-paper
          • Constructor-utilities
          • Grammar-printer
          • Parsing-tools
        • Vwsim
        • Isar
        • Wp-gen
        • Dimacs-reader
        • Pfcs
        • Legacy-defrstobj
        • Proof-checker-array
        • Soft
        • C
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Leftist-trees
        • Java
        • Taspi
        • Bitcoin
        • Riscv
        • Des
        • Ethereum
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Tree

    Tree-case

    Case macro for the different kinds of tree structures.

    This is an ACL2::fty sum-type case macro, typically introduced by fty::defflexsum or fty::deftagsum. It allows you to safely check the type of a tree structure, or to split into cases based on its type.

    Short Form

    In its short form, tree-case allows you to safely check the type of a tree structure. For example:

    (tree-case x :leafterm)

    is essentially just a safer alternative to writing:

    (equal (tree-kind x) :leafterm)

    Why is using tree-case safer? When we directly inspect the kind with equal, there is no static checking being done to ensure that, e.g., :leafterm is a valid kind of tree structure. That means there is nothing to save you if, later, you change the kind keyword for this type from :leafterm to something else. It also means you get no help if you just make a typo when writing the :leafterm symbol. Over the course of developing VL, we found that such issues were very frequent sources of errors!

    Long Form

    In its longer form, tree-case allows you to split into cases based on the kind of structure you are looking at. A typical example would be:

    (tree-case x
      :leafterm ...
      :leafrule ...
      :nonleaf ...)

    It is also possible to consolidate ``uninteresting'' cases using :otherwise.

    For convenience, the case macro automatically binds the fields of x for you, as appropriate for each case. That is, in the :leafterm case, you can use fty::defprod-style foo.bar style accessors for x without having to explicitly add a leafterm b* binder.