LISP使用负数作为指数

-1 lisp common-lisp

我一直在努力解决以下Common Lisp问题:

题

到目前为止我有这个:

(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)))
Run Code Online (Sandbox Code Playgroud)

但我一直在exp函数附近得到错误"type-error"...有人可以帮我弄清楚出了什么问题吗?

Ren*_*nzo 5

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

((/ 1 (+ 1 (exp (- 0 sum)))))
Run Code Online (Sandbox Code Playgroud)

是一个无效的表达式(它有两个括号).改变它

(/ 1 (+ 1 (exp (- 0 sum))))
Run Code Online (Sandbox Code Playgroud)

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