(define (quadratic_solver a b c)
(cond ( (< -(* b b)(* 4 a c) 0) (write "no result"))
( else ( / (+((* -1 b) (sqrt -(* b b)(* 4 a c)))) (* 2
a)) )
)
)
I encounter following errors:
Warning: invalid arguments
(< - (* b b) (* 4 a c) 0)
(procedure wants: (:real :real &rest :real))
(arguments are: ((proc (:number
&opt :number) :number) :number :number :exact-integer))
(&warning)
Warning: non-procedure in operator position
((* -1 b) (sqrt - (* b b) (* 4 a c)))
(procedure: #{Type :number #f #f})
(&warning)
Warning: wrong number of arguments
(sqrt - (* b b) (* 4 a c))
(procedure wants: (:number))
(arguments are: ((proc (:number
&opt :number) :number) :number :number))
(&warning)
Please help me!!
Unary minus is an procedure and should be parentesized together with
its argument.
E.g. your condition
(< -(* b b)(* 4 a c) 0)
should look like
(< (- (* b b) (* 4 a c)) 0).
The same with all other minus sign appearances in your code.
Good luck,
Sergey
Sergey
Hi, Ravi.
I am starting college too, and I know how you are feeling about
Scheme; however, believe me, if it were Java or Python, your the
situation would be much worse. I am using Bigloo; therefore, I solved
your problem in Bigloo. Since I do not like to use interpreters, I was
forced to add a function to read the three numbers from the command
line. However, I think that your problem is the misplaced/missing
parentheses.
(module quadratic (main main))
(define (quadratic_solver a b c)
(cond ( (< (-(* b b)(* 4 a c)) 0) (write "no result"))
( else ( / (+ (* -1 b) (sqrt (-(* b b)(* 4 a c)))) (*
2 a)) )
)
)
(define (main argv)
(print (with-handler (lambda(exc) (print "Error!"))
(let ( (a (string->number(cadr argv)))
(b (string->number (caddr argv)))
(c (string->number (cadddr argv)) ))
(quadratic_solver a b c)))))
Pay attention: You misplaced/missed quite a few parentheses. Whenever
you start a new operation, put it between parentheses. In your case,
the minus operation was not between parentheses. BTW, my colleagues
and I started a page for solving assignments; we are using Bigloo and
Stalin. If you want to participate, the address is:
Feel free to write for any one of us. We are there to help each other
to get good marks.
And you have incorrect parentheses in this combination:
( / (+((* -1 b) (sqrt -(* b b)(* 4 a c)))) (* 2 a))
It should be:
(/ (+ (* -1 b)
(sqrt (- (* b b) (* 4 a c)))
(* 2 a))
Also, proper indentation makes code more readable.
Sergey