I want to write a program to find the roots of the quadratic equation in Scheme. I used LET for certain bindings.
(define roots-with-let
(λ (a b c)
(let ((4ac (* 4 a c))
(2a (* 2 a))
(discriminant (sqrt ( - (* b b) (4ac)))))
(cons ( / ( + (- b) discriminant) 2a)
( / ( - (- b) discriminant) 2a)))))
I defined the discriminant with 4ac
since I did not want (* 4 a c)
. Even though I have defined (4ac (* 4 a c))
, it is giving me this error:
expand: unbound identifier in module in:
4ac
.
My question is how is let evaluated (what order)? And if i want 4ac
in my let
should i write another inner let
? Is there a better way to do this?