Generate the code for the cases of a sum type.
(deffold-map-gen-sum-cases type fix prods suffix
targets extra-args overrides fty-table)
→
keyword+term-listWe generate a list
For each case, first we check whether there is an overriding term, in which case we use that as the term for the case. Otherwise, we map over the fields.
Function:
(defun deffold-map-gen-sum-cases (type fix prods suffix targets extra-args overrides fty-table) (declare (xargs :guard (and (symbolp type) (symbolp fix) (flexprod-listp prods) (symbolp suffix) (symbol-listp targets) (true-listp extra-args) (alistp overrides) (alistp fty-table)))) (let ((__function__ 'deffold-map-gen-sum-cases)) (declare (ignorable __function__)) (b* (((when (endp prods)) nil) (prod (car prods)) (kind (flexprod->kind prod)) ((unless (keywordp kind)) (raise "Internal error: kind ~x0 is not a keyword." kind)) (term (b* ((term-assoc (assoc-equal (cons type kind) overrides)) ((when term-assoc) (cdr term-assoc))) (deffold-map-gen-sum-case type fix prod suffix targets extra-args fty-table)))) (list* kind term (deffold-map-gen-sum-cases type fix (cdr prods) suffix targets extra-args overrides fty-table)))))
Theorem:
(defthm true-listp-of-deffold-map-gen-sum-cases (b* ((keyword+term-list (deffold-map-gen-sum-cases type fix prods suffix targets extra-args overrides fty-table))) (true-listp keyword+term-list)) :rule-classes :rewrite)