File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Expand file tree Collapse file tree 1 file changed +16
-5
lines changed 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 ))))))
You can’t perform that action at this time.
0 commit comments