eq/eql/equal 如何与列表一起使用?

How the eq/eql/equal works whit list?

我是一名学生,我需要一些帮助,我正在编写一个代码来检测回文(单词、短语或序列,向后读与正向读相同)我有这个代码,但 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"))))

待办事项:

  • 确保 ab 得到评估以进行比较
  • 使用EQUAL作为测试
  • 使用(reverse b)
  • 的结果
  • 不要将 b 设置为文字常量
  • 确保出现输出