File tree 2 files changed +17
-13
lines changed
2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change 46
46
# :equal-expression
47
47
# :truth
48
48
# :truth-infix
49
+ # :*output-stream*
49
50
# :main)
50
51
(:nicknames " INFERENCE" ))
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*
9
+ " Default stream to write the results" )
8
10
9
11
(defun propositionp (symbol )
10
12
" Check if the given SYMBOL can be a proposition (letters)"
134
136
do (nsubst (intern-symbol op-name) op-name exp )
135
137
finally (return exp )))
136
138
137
- (defun princ-n (string n )
139
+ (defun princ-n (string &optional (n 1 ) )
138
140
" Just print the STRING by N times"
139
- (dotimes (_ n) (princ string )))
141
+ (dotimes (_ n)
142
+ (format *output-stream* " ~a " string )))
140
143
141
144
(defun print-bar (spaces)
142
- (princ " +" )
145
+ (princ-n " +" 1 )
143
146
(princ-n " -" (1- (reduce #' + spaces)))
144
- (princ " +" )
145
- (princ #\newline ))
147
+ (princ-n " +" 1 )
148
+ (princ-n #\newline ))
146
149
147
150
(defun last-element (l)
148
151
(car (last l)))
@@ -175,25 +178,25 @@ a tautology."
175
178
collect (concatenate ' string " " p " |" )))
176
179
(spaces (mapcar #' length printable-header)))
177
180
(print-bar spaces)
178
- (princ " |" )
181
+ (princ-n " |" )
179
182
(loop for exp in printable-header
180
- do (princ exp )
181
- finally (princ #\newline ))
183
+ do (princ-n exp )
184
+ finally (princ-n #\newline ))
182
185
(print-bar spaces)
183
186
(loop for n-value from 1 below n-values
184
187
do (progn
185
- (princ " |" )
188
+ (princ-n " |" )
186
189
(loop for n-exp from 0 below (length header)
187
190
do (let* ((space (nth n-exp spaces))
188
191
(half-space (floor (- space 2 ) 2 ))
189
192
(val (nth n-value (nth n-exp truth-table))))
190
193
(princ-n " " half-space)
191
- (princ val)
194
+ (princ-n val)
192
195
(princ-n " " half-space)
193
196
(if (oddp space )
194
- (princ " |" )
195
- (princ " |" ))))
196
- (princ #\newline )))
197
+ (princ-n " |" )
198
+ (princ-n " |" ))))
199
+ (princ-n #\newline )))
197
200
(print-bar spaces)))
198
201
199
202
(defmacro truth (exp )
You can’t perform that action at this time.
0 commit comments