1

私はLispが初めてで、機能に問題があります:

(setf (symbol-function 'reduce-our)
    #'(lambda(new-expression)
            (setf expression nil)
              (loop while (not (equal new-expression expression)) do
                        (setf expression new-expression)
                        (setf new-expression (reduce-once-our expression))
                        (if (not (equal 'new-expression 'expression))
                            (format t " ==> ~A Further reductions are impossible.~%"
                             new-expression)
            new-expression))))

(reduce-our '(^ x => x))

これは次のエラーです:

Error: The value ^ is not of the expected type NUMBER.

LISP が入力リストを while ループで評価しようとしていると思っていたのですが、

(not (equal nil '(^ x => x)))

正常に動作し、関数が同じチェックを行うと確信しています。そう。このエラーが発生する場所と理由がわかりません。

4

1 に答える 1

3

この関数でエラーが発生しますか? バックトレースを見る必要があります。

さらに:

(setf (symbol-function 'reduce-our)
   #'(lambda (new-expression)
      ...))

通常、次のように書かれています

(defun reduce-our (new-expression)
   ...)

それで:

(setf (symbol-function 'reduce-our)
  #'(lambda(new-expression)
      (setf expression nil) ...

変数はどこにexpression導入されますか? それは宣言されていません。値を設定しても、変数は宣言されません。

それで:

while (not (foo ...))

ただです

until (foo ...)

(if (not (foo)) a b)

(if (foo) b a)

また、インデントを改善します。Lisp のエディターがそれを行います。あなたや他の人にとって読みやすさが向上します。

于 2013-04-26T09:09:53.307 に答える