LISP使用负数作为指数

时间:2019-02-03 17:04:59

标签: lisp common-lisp

我一直在尝试解决以下Common Lisp问题:

Question

到目前为止,我有这个:

(defun activation (type sum) 
  "(type sum)
Returns the activation value of a connectionist unit 
given a sum of products of input activations x 
corresponding connection weights."
  (cond ((equal type 'sigmoid) (- (/ 1 (+ 1 (exp (- 0 sum)))) 0.5))
        ((equal type 'asigmoid) ((/ 1 (+ 1 (exp (- 0 sum))))))
        (t 'unknown-type)))

但是我总是在exp函数附近收到错误“ type-error” ...有人可以帮助我找出问题所在吗?

1 个答案:

答案 0 :(得分:5)

您的代码中存在语法错误:

((/ 1 (+ 1 (exp (- 0 sum)))))

是无效的表达式(有两个括号)。在其中更改

(/ 1 (+ 1 (exp (- 0 sum))))

在Lisp语言中,每个单独的括号都是重要的语法标记,而不是在其他语言中,(a + b)((a + b))表示相同的表达式。

相关问题