Add a cap to th number of variables supported

This commit is contained in:
2025-12-20 16:35:32 -08:00
parent 65970adfe1
commit 7f6872c0ea

View File

@ -38,6 +38,10 @@
collect (cons (cons var nil) entry))
finally (return (mapcar 'reverse perms))))
(defconstant +maximum-variables+ 12
"The maximum number of variables allowed when including variables in the table
output.")
(defun create-truth-table (prop &key (vars (discover-variables prop))
(include-intermediate t) (include-vars t))
"Evaluate PROP with all possible combinations of truth values for its
@ -49,6 +53,10 @@ if it is excluded, `discover-variables' will be used to generate it."
((null vars)
(list (list (cons prop (eval-proposition prop '())))))
(t
(when (> (length vars) +maximum-variables+)
(error 'proposition-eval-error
:message (format nil "Got ~A variables when the max is ~A"
(length vars) +maximum-variables+)))
(loop for perm in (permute-variables vars)
for (value sub-map) = (multiple-value-list
(eval-proposition prop perm))