运行lisp程序遇到:should be a lambda expression,如何解决?
(defun int-to-binary (alist)
    (setq n (- length(alist) 1))
    (setq result 0)
    (loop for x in alist
        do(setq result (+ result (* x (expt 2 n)))
        (setq n (- n 1))
        )
    )
    (format t "~d" result)

(int-to-binary '(1 0 1 1))

报错如下:

*** - SYSTEM::%EXPAND-FORM: (SETQ RESULT (+ RESULT (* X (EXPT 2 N)))) should be a lambda expression

这个程序是要解决如下问题的:

Write a LISP function binary-to-int that converts a binary number that is given as list
comprising only 0 and 1 into a integer. For example:
(binary-to-int ’()) returns nil, because the empty set is not a representation of a binary number.
(binary-to-int ’(1 0)) returns 2
(binary-to-int ’(0 1)) returns 1
(binary-to-int ’(0)) returns 0
(binary-to-int ’(1 1 1 0)) returns 14

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问