From 58f4cc3084d4ad82835cc56e159ba180bb18985c Mon Sep 17 00:00:00 2001 From: Marcus Kammer Date: Tue, 19 Sep 2023 16:24:24 +0200 Subject: [PATCH] Use compile time type checking with composite list type --- src/pattern/questionnaire.lisp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pattern/questionnaire.lisp b/src/pattern/questionnaire.lisp index dc054a2..0a9fcb9 100644 --- a/src/pattern/questionnaire.lisp +++ b/src/pattern/questionnaire.lisp @@ -58,6 +58,10 @@ " A question is a list of keyword value pairs." '(and list (satisfies questionp))) +(deftype composite-list () + '(or (satisfies choicesp) + (satisfies questionp))) + (defun resolve-input-type (type) "Resolve the given input TYPE keyword to the corresponding HTML input type. @@ -149,6 +153,7 @@ Example: `((process-choice ,group ,choice)))) (: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) "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: A list of sublists, each starting with a keyword." ;; Initialize result and current-list - (unless (or (choicesp lst) (questionp lst)) - (error "Invalid type for LST. Expected a 'choices' or 'question'.")) (let ((result '()) (current-list '())) ;; Loop through each item in plist