Giving a symbol a negative value in lisp

为君一笑 提交于 2019-12-11 03:43:09

问题


I'm very new to lisp and I am working on basic syntax. I am trying to convert:
r1 = (-b + sqrt(b^2 - 4*a*c))/(2*a)
into a lisp format. The only problem I think I am having is that I cannot get lisp to recognize -b as the negative value of my symbol b. This is what I have so far from the lisp prompt:

[17]> (setq a 1L0)
1.0L0
[18]> (setq b -1L0)
-1.0L0
[19]> (setq c -1L0)
-1.0L0
[20]> (setq r1 (+ (/ (sqrt (- (power b 2) (* (* 4 a) c))) (* 2 a)) -b))

*** - EVAL: variable -B has no value
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead of -B.
STORE-VALUE    :R2      You may input a new value for -B.
ABORT          :R3      Abort main loop

回答1:


use

(- b)

to negate b. It is equivalent to

(- 0 b)


来源:https://stackoverflow.com/questions/15592596/giving-a-symbol-a-negative-value-in-lisp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!