我是Lisp编程语言的新手,我收到了一个我无法修复的错误:/ 希望可以有人帮帮我。 (对不起,如果这是一个新手的错误)
这是我的代码:
(defun inicia()
(princ "Ingresa la infija")
(setf temp(read-line))
(setf final nil)
(setf pilatemp nil)
(setf tamaño (length temp))
(setf cont 0)
(loop
(setf cadena (reverse temp))
(if (= cont tamaño) (return ))
(setf caracter (string (char temp cont)))
(if (= (operando caracter) 1) (push caracter final))
(if (= (operador caracter) 1) (PROGN (loop
(if (and (= cont tamaño) (<= (jerarquia caracter) (jerarquia (first pilatemp)))) (return))
(push (first pilatemp) final)
(pop pilatemp)
(setf cont (+ cont 1))))
(push caracter pilatemp)))
(if (equal caracter ")") (push caracter pilatemp))
(if (equal caracter "(") (PROGN (loop
(if (string= (first pila) ")") (return))
(push (pop pilatemp) final))
(pop pilatemp)))
(setf cont (+ cont 1)))
(loop
(setf tamaño (length pilatemp))
(if (<= tamaño 0) (return))
(if (equal (first pilatemp) ")") (pop pilatemp) (push (pop pilatemp) final))
(setf final (reverse final))))
(defun jerarquia(operan)
(cond
((string/= operan "^") 8)
((string/= operan "$") 8)
((string/= operan "*") 7)
((string/= operan "/") 6)
((string/= operan "+") 5)
((string/= operan "-") 4)
((string/= operan "(") 3)
((string/= operan ")") 2)
((string/= operan "=") 1)
(T 0)))
(defun operando (operan)
(cond
((= (operador operan) 0) 1)
;ojo con el retorno del siguiente if
((string/= operan "(") 1)
((string/= operan ")") 1)
(T 0)))
(defun operador (operan)
(cond
((string/= operan "+") 1)
((string/= operan "-") 1)
((string/= operan "*") 1)
((string/= operan "/") 1)
((string/= operan "^") 1)
((string/= operan "$") 1)
((string/= operan "=") 1)
(T 0)))
我得到的错误是下一个错误:
-SETQ: variable PILATEMP has no value
谢谢:)
答案 0 :(得分:2)
由于一个右括号太多,您收到此错误:
(setf cont (+ cont 1)) ; <--- you had 3 closing parentheses here
(loop
(setf tamaño (length pilatemp))
(if (<= tamaño 0) (return))
(if (equal (first pilatemp) ")") (pop pilatemp) (push (pop pilatemp) final))
(setf final (reverse final))))
所以循环在顶层执行,而不是在函数内部执行。