File tree Expand file tree Collapse file tree 5 files changed +39
-11
lines changed Expand file tree Collapse file tree 5 files changed +39
-11
lines changed Original file line number Diff line number Diff line change 8
8
:description " An Inference Engine using Propositional Calculus"
9
9
:author " Manoel Vilela <[email protected] >"
10
10
:license " BSD"
11
- :version " 0.1 .0"
11
+ :version " 0.2 .0"
12
12
:serial t
13
13
:pathname " src"
14
14
:components ((:file " package" )
25
25
:description " Lisp Inference Test Suit"
26
26
:author " Manoel Vilela <[email protected] >"
27
27
:license " BSD"
28
- :version " 0.1 .0"
28
+ :version " 0.2 .0"
29
29
:serial t
30
30
:pathname " t"
31
31
:depends-on (:lisp-inference :prove )
Original file line number Diff line number Diff line change 40
40
# :make-biconditional
41
41
# :*valid-operators*
42
42
# :prefix-to-infix
43
+ # :infix-to-prefix
43
44
# :print-truth-table ; ; truth-table.lisp
44
45
# :eval-expression
45
46
# :equal-expression
Original file line number Diff line number Diff line change 112
112
113
113
114
114
(defun infix-to-prefix (exp )
115
- (cond ((atom exp ) exp )
116
- ((null (cdr exp )) (infix-to-prefix (car exp )))
117
- (t (list (cadr exp )
118
- (infix-to-prefix (car exp ))
119
- (infix-to-prefix (cddr exp ))))))
115
+ " INFIX-TO-PREFIX translate a infix expression to a prefix expression.
116
+
117
+ This function assumes that exp it is not ambiguous.
118
+ In that case, use a completly 'parenthesed' expression
119
+
120
+ Returns a new prefixed list.
121
+ "
122
+ (cond ((atom exp ) exp )
123
+ ((and (listp exp )
124
+ (= 2 (length exp )))
125
+ (list (car exp )
126
+ (infix-to-prefix (cdr exp ))))
127
+ ((null (cdr exp )) (infix-to-prefix (car exp )))
128
+ (t (list (cadr exp )
129
+ (infix-to-prefix (car exp ))
130
+ (infix-to-prefix (cddr exp ))))))
Original file line number Diff line number Diff line change 3
3
4
4
(in-package :lisp-inference )
5
5
6
+ (defparameter *truth-string* " T" )
7
+ (defparameter *false-string* " F" )
8
+
6
9
(defun propositionp (symbol )
7
10
" Check if the given SYMBOL can be a proposition (letters)"
8
11
(and (atom symbol )
106
109
107
110
(defun pretty-values (v)
108
111
(if (not (null v))
109
- " T "
110
- " F " ))
112
+ *truth-string*
113
+ *false-string* ))
111
114
112
115
(defun prepare-table (evaluated-cases)
113
116
" Get the evaluated cases after EVAL-OPERATIONS
@@ -204,10 +207,10 @@ a tautology."
204
207
205
208
206
209
(defun main ()
207
- (format t " Example of usage: (^ p q)~% Operators: ~a ~% " *valid-operators* )
210
+ (format t " Example of usage: (p ^ q)~% Operators: ~a ~% " *valid-operators* )
208
211
(handler-case (loop do (princ " TRUTH-TABLE> " )
209
212
do (force-output )
210
- do (print-truth-table (read )))
213
+ do (print-truth-table (infix-to-prefix ( read ) )))
211
214
(end-of-file () )
212
215
#+ sbcl (sb-sys :interactive-interrupt () nil ))
213
216
Original file line number Diff line number Diff line change 102
102
' (p))
103
103
" EQUAL EXPRESSION 2" )
104
104
105
+ (diag " == Infix Parsing" )
106
+
107
+ (is (infix-to-prefix ' (~ (p v q)))
108
+ ' (~ (v p q)))
109
+
110
+ (is (infix-to-prefix ' (p => q))
111
+ ' (=> p q))
112
+
113
+ (is (infix-to-prefix ' ((p v q) <=> ((~ p) ^ (~ q))))
114
+ ' (<=> (v p q)
115
+ (^ (~ p)
116
+ (~ q))))
117
+
105
118
(finalize)
You can’t perform that action at this time.
0 commit comments