Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help me identify error here: beginners question

0 views
Skip to first unread message

Ravi

unread,
Mar 15, 2008, 5:57:40 PM3/15/08
to
The following code here is to find one of the roots of the quadratic
equation a*x^2 + b*x + c = 0. I use MIT/GNU scheme. Can You please
help me why following errors occur and what they mean:

(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!!

skhe...@gmail.com

unread,
Mar 15, 2008, 8:07:52 PM3/15/08
to
Ravi,

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

skhe...@gmail.com

unread,
Mar 15, 2008, 8:10:42 PM3/15/08
to
Sorry,
I meant binary minus.
However for unary minus my point is valid too.

Sergey

phi5...@yahoo.ca

unread,
Mar 15, 2008, 8:20:19 PM3/15/08
to


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:

code.google.com/p/stalingui

Feel free to write for any one of us. We are there to help each other
to get good marks.

skhe...@gmail.com

unread,
Mar 15, 2008, 8:22:13 PM3/15/08
to
Ravi,

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

0 new messages