Use compile time type checking with composite list type

This commit is contained in:
Marcus Kammer 2023-09-19 16:24:24 +02:00
parent 5712ae7960
commit 58f4cc3084

View file

@ -58,6 +58,10 @@
" A question is a list of keyword value pairs." " A question is a list of keyword value pairs."
'(and list (satisfies questionp))) '(and list (satisfies questionp)))
(deftype composite-list ()
'(or (satisfies choicesp)
(satisfies questionp)))
(defun resolve-input-type (type) (defun resolve-input-type (type)
"Resolve the given input TYPE keyword to the corresponding HTML input type. "Resolve the given input TYPE keyword to the corresponding HTML input type.
@ -149,6 +153,7 @@ Example:
`((process-choice ,group ,choice)))) `((process-choice ,group ,choice))))
(:hr :class (spacing :property "m" :side "y" :size 4))))) (:hr :class (spacing :property "m" :side "y" :size 4)))))
(declaim (ftype (function (composite-list) list) split-list-by-keyword))
(defun split-list-by-keyword (lst) (defun split-list-by-keyword (lst)
"Splits a list (LST) into a list of smaller lists, each starting with a keyword. "Splits a list (LST) into a list of smaller lists, each starting with a keyword.
@ -170,8 +175,6 @@ Example 2 (Key-Grouped List):
Returns: Returns:
A list of sublists, each starting with a keyword." A list of sublists, each starting with a keyword."
;; Initialize result and current-list ;; Initialize result and current-list
(unless (or (choicesp lst) (questionp lst))
(error "Invalid type for LST. Expected a 'choices' or 'question'."))
(let ((result '()) (let ((result '())
(current-list '())) (current-list '()))
;; Loop through each item in plist ;; Loop through each item in plist