[我是一个学生,我需要一点帮助,我正在做一个代码以检测回文(单词,短语或序列,其顺序与向后读相同),我有这段代码,但是eql总是给我错误,我不知道什么是错误的
(defun palindromo()
(let ((a) (b '(itati)))
(print "Ingrese una lista: ")
(setq a(read))
(reverse b )
(if (eql '(a) '(b) )
(print "Verdadero")
(print "Falso"))
);let
);defun
这是唯一的测试版本,原始版本可以使用任何单词或数字
(defun palindromo()
(let ((a) (b '(itati)))
(print "Ingrese una lista: ")
(setq a(read))
(reverse b )
(if (eql '(a) '(b) )
(print "Verdadero")
(print "Falso"))
);let
);defun
您的代码大部分不可读。您应该花一些时间来格式化和缩进代码。
问题:
(defun palindromo ()
(let ((a)
(b '(itati))) ; literal data, don't modify that later
(print "Ingrese una lista: ")
; needs a call to (finish-output) in portable code
; to make sure that the output actually gets printed
(setq a (read))
(reverse b) ; the value of the expression is not used
; also: don't change literal data!
(if (eql '(a) '(b) ) ; '(a) and '(b) are constant literal expressions
; a and b will never be evaluated
; thus the expression is always false
(print "Verdadero")
(print "Falso"))))
要做:
a
和b
得到评估以进行比较EQUAL
作为测试(reverse b)
的结果b
设置为文字常量