Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving a symbol a negative value in lisp

Tags:

lisp

clisp

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
like image 987
DLR Avatar asked Dec 27 '22 07:12

DLR


1 Answers

use

(- b)

to negate b. It is equivalent to

(- 0 b)
like image 143
uselpa Avatar answered Jan 02 '23 16:01

uselpa