|
22 | 22 | (defvar *proposition* "P => Q" "Default proposition") |
23 | 23 | (defvar *port* (find-port:find-port)) |
24 | 24 | (defvar *notes* |
25 | | - '("My lexer doesn't work very well with parenthesis." |
26 | | - "Please, don't be evil. Use less than 10 variables." |
| 25 | + '("Please, don't be evil. Use less than 10 variables." |
27 | 26 | "Yes, [+] it's a XOR. Mathematically: p ⊕ q." |
28 | 27 | "(=> ->) and (<=> <->) are aliases.")) |
29 | 28 |
|
|
40 | 39 | :initform nil |
41 | 40 | :accessor truth))) |
42 | 41 |
|
43 | | -(defun parse-string (string) |
44 | | - "Translate string to a list expression" |
45 | | - (if (and (str:starts-with-p "(" string) |
46 | | - (str:ends-with-p ")" string)) |
47 | | - (read-from-string string) |
48 | | - (read-from-string (str:concat "(" string ")")))) |
49 | | - |
50 | 42 | (defun truth-table (exp) |
51 | 43 | (with-output-to-string (s) |
52 | 44 | (let ((inference:*output-stream* s)) |
53 | | - (inference:print-truth-table (inference:infix-to-prefix exp))))) |
| 45 | + (inference:print-truth-table (inference:parse-logic exp))))) |
54 | 46 |
|
55 | | -(defun create-table (exp) |
| 47 | +(defun create-table (exp-string) |
56 | 48 | (make-instance 'table |
57 | | - :prop (format nil "~a" exp) |
58 | | - :truth (truth-table exp))) |
| 49 | + :prop exp-string |
| 50 | + :truth (truth-table exp-string))) |
59 | 51 |
|
60 | 52 | (defgeneric update-table (table exp)) |
61 | 53 |
|
62 | | -(defmethod update-table (table (exp list)) |
63 | | - (setf (prop table) (format nil "~a" exp)) |
| 54 | +(defmethod update-table (table (exp string)) |
| 55 | + (setf (prop table) exp) |
64 | 56 | (setf (truth table) (truth-table exp)) |
65 | 57 | (update table)) |
66 | 58 |
|
67 | | -(defmethod update-table (table (exp string)) |
68 | | - (update-table |
69 | | - table |
70 | | - (parse-string exp))) |
71 | | - |
72 | 59 | (defmethod render ((table table)) |
73 | 60 | (with-html |
74 | 61 | (:h1 :align "center" "Lisp Inference Truth Table System") |
|
100 | 87 |
|
101 | 88 | (defmethod weblocks/session:init ((app truth-table)) |
102 | 89 | (declare (ignorable app)) |
103 | | - (create-table (parse-string *proposition*))) |
| 90 | + (create-table *proposition*)) |
104 | 91 |
|
105 | 92 | (defun start (&optional (port *port*)) |
106 | 93 | (weblocks/debug:on) |
|
0 commit comments