DLR
DLR

Reputation: 187

Giving a symbol a negative value in lisp

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

Upvotes: 4

Views: 5444

Answers (1)

uselpa
uselpa

Reputation: 18917

use

(- b)

to negate b. It is equivalent to

(- 0 b)

Upvotes: 10

Related Questions