首页 > 解决方案 > 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)))

但是我在 exp 函数附近不断收到错误“类型错误”......有人可以帮我找出问题所在吗?

标签: lispcommon-lisp

解决方案


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

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

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

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

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


推荐阅读