问题
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