0

lispで関数を書いていますが、結果が得られません。関数は、式の原子の数を数えることです。

(defun count-atoms(exp)
'Return the total number of non-nil atoms in the expression'
(cond((null exp) 0)
     ((atom exp) 1)
     ( t (+ (count-atoms (first exp))
            (count-atoms (rest exp))))))

clispで実行すると、結果なしで次のようになります。

[3]> (count-atoms '(a b c))
(COND ((NULL EXP) 0) ((ATOM EXP) 1)
(T (+ (COUNT-ATOMS (FIRST EXP)) (COUNT-ATOMS (REST EXP)))))

誰か助けてもらえますか?

4

1 に答える 1

2

まったく結果が出てびっくりしました。エラーが発生します:

*** - PROGN: variable THE has no value
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead of THE.
STORE-VALUE    :R2      Input a new value for THE.
ABORT          :R3      Abort main loop

その理由は、CommonLispの文字列は二重引用符で囲む必要があるためです"Return ..."。一重引用符は、評価を防ぐためにのみ使用されます。

于 2012-09-29T18:58:34.920 に答える