File tree Expand file tree Collapse file tree 2 files changed +23
-15
lines changed Expand file tree Collapse file tree 2 files changed +23
-15
lines changed Original file line number Diff line number Diff line change 5
5
6
6
(defparameter *truth-string* " T" )
7
7
(defparameter *false-string* " F" )
8
- (defparameter *output-stream* *standard-output*
8
+ (defparameter *output-stream* nil
9
9
" Default stream to write the results" )
10
10
11
11
(defun propositionp (symbol )
@@ -211,10 +211,11 @@ a tautology."
211
211
212
212
(defun main ()
213
213
(format t " Example of usage: (p ^ q)~% Operators: ~a ~% " *valid-operators* )
214
- (handler-case (loop do (princ " TRUTH-TABLE> " )
215
- do (force-output )
216
- do (print-truth-table (infix-to-prefix (read ))))
217
- (end-of-file () )
218
- #+ sbcl (sb-sys :interactive-interrupt () nil ))
219
-
220
- (format t " ~% Goodbye!~% " ))
214
+ (let ((*output-stream* *standard-output* ))
215
+ (handler-case (loop do (princ-n " TRUTH-TABLE> " )
216
+ do (force-output *output-stream* )
217
+ do (print-truth-table (infix-to-prefix (read ))))
218
+ (end-of-file () )
219
+ #+ sbcl (sb-sys :interactive-interrupt () nil ))
220
+
221
+ (format t " ~% Goodbye!~% " )))
Original file line number Diff line number Diff line change 12
12
# :defapp)
13
13
(:export # :start
14
14
# :stop
15
- # :*propostion *
15
+ # :*proposition *
16
16
# :*port* )
17
17
(:nicknames # :webapp))
18
18
19
19
(in-package lisp-inference/web)
20
20
21
- (defvar *proposition* ' ( P => Q) " Default proposition" )
21
+ (defvar *proposition* " P => Q" " Default proposition" )
22
22
(defvar *port* (find-port :find-port))
23
23
24
24
(defapp truth-table
34
34
:initform nil
35
35
:accessor truth)))
36
36
37
+ (defun parse-string (string )
38
+ " Translate string to a list expression"
39
+ (mapcar (lambda (x)
40
+ (intern (string-upcase x) :lisp-inference ))
41
+ (str :words string )))
42
+
43
+ (defun trim-paren (string )
44
+ (string-trim ' (#\( #\) ) string ))
45
+
37
46
(defun truth-table (exp )
38
47
(with-output-to-string (s)
39
48
(let ((inference :*output-stream* s))
57
66
(defmethod update-proposition (table (string string ))
58
67
(update-proposition
59
68
table
60
- (mapcar (lambda (x)
61
- (intern (string-upcase x)))
62
- (str :words (string-trim ' (#\( #\) ) string )))))
69
+ (parse-string string )))
63
70
64
71
(defmethod render ((table table))
65
72
(with-html
68
75
(update-proposition table prop)))
69
76
(:input :type " text"
70
77
:name " prop"
71
- :placeholder (prop table))
78
+ :placeholder (trim-paren ( prop table) ))
72
79
(:input :type " submit"
73
80
:value " Eval" ))
74
81
(:pre (truth table))))
79
86
80
87
(defmethod weblocks/session :init ((app truth-table))
81
88
(declare (ignorable app))
82
- (create-table *proposition* ))
89
+ (create-table (parse-string *proposition* ) ))
83
90
84
91
(defun start (&optional (port *port* ))
85
92
(weblocks/debug :on)
You can’t perform that action at this time.
0 commit comments