这个常见的lisp代码有什么问题?

这个常见的lisp代码有什么问题?,lisp,common-lisp,Lisp,Common Lisp,基本上,我尝试评估下面的函数,但不断出现以下错误: WARNING : MAINDIA is neither declared nor bound, it will be treated as if it were declared SPECIAL. WARNING : SOUT is neither declared nor bound, it will be treated as if it were declared SPECIAL. WARNING : NORT is neither

基本上,我尝试评估下面的函数,但不断出现以下错误:

 WARNING :
MAINDIA is neither declared nor bound,
it will be treated as if it were declared SPECIAL.
WARNING :
SOUT is neither declared nor bound,
it will be treated as if it were declared SPECIAL.
WARNING :
NORT is neither declared nor bound,
it will be treated as if it were declared SPECIAL.
*** - NIL: variable MAINDIA has no value
The following restarts are available:
ABORT          :R1      Abort debug loop
ABORT          :R2      Abort debug loop
ABORT          :R3      Abort debug loop
ABORT          :R4      Abort debug loop
ABORT          :R5      Abort debug loop
ABORT          :R6      Abort debug loop
ABORT          :R7      Abort debug loop
ABORT          :R8      Abort main loop
当我尝试从互联网上复制粘贴一个示例时,它可以工作,但当我手动将其输入解释器时,它就不工作了。另外,我正在从emacs运行CLISP

代码:


注意:我使用的是CLISP 2.48

很可能,您的问题在于emacs,而不是代码,因为它在评论员和我的lisps中运行良好。我不再使用emacs了,所以下面的解决方案可能已被弃用或完全错误,但是如果您通过emacs启动emacs--debug init并收到错误消息,那么您会遇到一些安装问题,而不是代码问题。另外,问题似乎在于您的lisp实现,而不是lisp编写。如果它是您的lisp实现,只需重新构建就可以了。如果这是你的设置,我很肯定有一些非常详尽的错误和修复列表。很好的搜索。

试试
let
,而不是
let*
——你们并没有在彼此之间使用定义。@Marcin你们错了,他确实在使用它们。无论如何,这段代码是完全有效的,并且在SBCL中运行良好。检查
let*
的值是什么(可能是因为您在某个地方重新定义了它吗?@VsevolodDyomkin:Only
diag
,但是是的-它应该是有效的,这就是我建议尝试let的原因。sbcl 1.0.55中没有返回错误。在这里的CLISP 2.49和sbcl 1.0.53中都可以正常工作。如果它在复制和粘贴时起作用,但在键入时不起作用,那么(假设您没有打字),它听起来像是终端/emacs问题,而不是代码问题。你在用粘液吗?
(defun diagonal-mast (sq)
  (let* ((maindia #x8040201008040201)
         (diag (- (* 8 (logand sq 7))
                  (logand sq 56)))
         (nort (logand (- diag)
                       (ash diag -31)))
         (sout (logand diag (ash (- diag) -31))))
    (ash (ash maindia (- sout))
         nort)))