• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • 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
      • Riscv
      • Taspi
      • Bitcoin
      • 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
      • Aleo
        • Aleobft
        • Aleovm
        • Leo
          • Grammar
          • Early-version
            • Json2ast
            • Testing
            • Definition
              • Flattening
              • Abstract-syntax
              • Dynamic-semantics
                • Execution
                • Values
                  • Int-valuep
                  • Value-option
                  • Type-of-value
                  • Value-option-result
                  • Value-list-result
                  • Name+value
                  • Value-result
                  • Make-int-value
                  • Type-map-of-value-map
                  • Name+type-of-name+value
                  • Int-value-bound-theorems
                  • Int-value-to-int
                  • Int-value-numbits
                  • Value/valuelist
                    • Value
                      • Valuep
                      • Value-case
                        • Value-equiv
                        • Value-struct
                        • Value-kind
                        • Value-u64
                        • Value-u32
                        • Value-u16
                        • Value-u128
                        • Value-tuple
                        • Value-string
                        • Value-i64
                        • Value-i32
                        • Value-i16
                        • Value-i128
                        • Value-bool
                        • Value-address
                        • Value-u8
                        • Value-scalar
                        • Value-i8
                        • Value-group
                        • Value-field
                        • Value-fix
                        • Value-count
                      • Value-list
                      • Value-map
                    • *most-positive-i8*
                    • *most-positive-i64*
                    • *most-positive-i32*
                    • *most-positive-i16*
                    • *most-positive-i128*
                    • *most-negative-i8*
                    • *most-negative-i64*
                    • *most-negative-i32*
                    • *most-negative-i16*
                    • *most-negative-i128*
                    • *greatest-u8*
                    • *greatest-u64*
                    • *greatest-u32*
                    • *greatest-u16*
                    • *greatest-u128*
                  • Dynamic-environments
                  • Arithmetic-operations
                  • Curve-parameterization
                  • Shift-operations
                  • Errors
                  • Value-expressions
                  • Locations
                  • Input-execution
                  • Edwards-bls12-generator
                  • Equality-operations
                  • Logical-operations
                  • Program-execution
                  • Ordering-operations
                  • Bitwise-operations
                  • Literal-evaluation
                  • Type-maps-for-struct-components
                  • Output-execution
                  • Tuple-operations
                  • Struct-operations
                • Compilation
                • Static-semantics
                • Concrete-syntax
        • Bigmems
        • Builtins
        • Execloader
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Community
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Value

    Value-case

    Case macro for the different kinds of value 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 value structure, or to split into cases based on its type.

    Short Form

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

    (value-case x :bool)

    is essentially just a safer alternative to writing:

    (equal (value-kind x) :bool)

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

    Long Form

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

    (value-case x
      :bool ...
      :u8 ...
      :u16 ...
      :u32 ...
      :u64 ...
      :u128 ...
      :i8 ...
      :i16 ...
      :i32 ...
      :i64 ...
      :i128 ...
      :field ...
      :group ...
      :scalar ...
      :address ...
      :string ...
      :tuple ...
      :struct ...)

    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 :bool case, you can use fty::defprod-style foo.bar style accessors for x without having to explicitly add a bool b* binder.