Make web server
This commit is contained in:
41
table.lisp
41
table.lisp
@ -15,13 +15,18 @@
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
(in-package :truth-table/base)
|
||||
|
||||
(defun flatten-tree (tree)
|
||||
"Flatten TREE into a single list."
|
||||
(if (atom tree)
|
||||
(list tree)
|
||||
(apply 'append (mapcar 'flatten-tree tree))))
|
||||
|
||||
(defun discover-variables (prop)
|
||||
"Return a list of all the variables in PROP, in left to right order."
|
||||
(cond
|
||||
((stringp prop)
|
||||
(list prop))
|
||||
((listp prop)
|
||||
(mapcan 'discover-variables (cdr prop)))))
|
||||
(let ((vars))
|
||||
(dolist (item (flatten-tree prop) (nreverse vars))
|
||||
(when (stringp item)
|
||||
(pushnew item vars :test 'equal)))))
|
||||
|
||||
(defun permute-variables (vars)
|
||||
"Return a list of alists, each with a different permutation of VARS."
|
||||
@ -38,17 +43,21 @@
|
||||
"Evaluate PROP with all possible combinations of truth values for its
|
||||
variables. If supplied VARS should be a list of all the know variables in PORP,
|
||||
if it is excluded, `discover-variables' will be used to generate it."
|
||||
(if (null vars)
|
||||
(list (list (cons prop (eval-proposition prop '()))))
|
||||
(loop for perm in (permute-variables vars)
|
||||
for (value sub-map) = (multiple-value-list
|
||||
(eval-proposition prop perm))
|
||||
collect
|
||||
(append (when include-vars perm)
|
||||
(when include-intermediate
|
||||
(delete-if (lambda (item) (equal prop (car item)))
|
||||
sub-map))
|
||||
(list (cons prop value))))))
|
||||
(cond
|
||||
((null prop)
|
||||
(list (list (cons nil nil))))
|
||||
((null vars)
|
||||
(list (list (cons prop (eval-proposition prop '())))))
|
||||
(t
|
||||
(loop for perm in (permute-variables vars)
|
||||
for (value sub-map) = (multiple-value-list
|
||||
(eval-proposition prop perm))
|
||||
collect
|
||||
(append (when include-vars perm)
|
||||
(when include-intermediate
|
||||
(reverse (delete-if (lambda (item) (equal prop (car item)))
|
||||
sub-map)))
|
||||
(list (cons prop value)))))))
|
||||
|
||||
(defun extract-truth-table-expressions (table)
|
||||
"Extract each expression from TABLE and return them as a list.
|
||||
|
Reference in New Issue
Block a user