From: Ravi
Subject: help me identify error here: beginners question
Date: 
Message-ID: <f4ab8c36-4492-403d-a28a-936608c85ab4@d21g2000prf.googlegroups.com>
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!!

From: danb
Subject: Re: help me identify error here: beginners question
Date: 
Message-ID: <c1727e68-2115-4be9-bd5e-4eeb713e7957@n58g2000hsf.googlegroups.com>
On Mar 15, 4:56 pm, Ravi <···········@gmail.com> wrote:
> Warning: invalid arguments
> (<  - (* b b) (* 4 a c)  0)
     ^                   ^
You need parentheses around the subtraction:
  (< (- (* b b) (* 4 a c)) 0)

Or more simply,
  (< (* b b) (* 4 a c))

> Warning: non-procedure in operator position
> (/ (+((* -1 b) (sqrt  - (* b b) (* 4 a c)))) (* 2 a))
       ^               ^
Now you have an extra one after the +,
and still missing one around the -:
  (/ (+ (* -1 b) (sqrt (- (* b b) (* 4 a c)))) (* 2 a))

> Please help me!!

As Pascal said, you need to count your parentheses.
There's one and only one pair around every operation.

------------------------------------------------
Dan Bensen
http://www.prairienet.org/~dsb/
From: danb
Subject: Re: help me identify error here: beginners question
Date: 
Message-ID: <cd45f768-c470-4e84-a61e-afa0b0035c82@c33g2000hsd.googlegroups.com>
On Mar 15, 6:46 pm, danb <·········@gmail.com> wrote:
>   (< (- (* b b) (* 4 a c)) 0)
> Or more simply,
>   (< (* b b) (* 4 a c))

Or even more simply, bind a name to the discriminant:

  (let ((b2-4ac (- (* b b) (* 4 a c))))
     ...

------------------------------------------------
Dan Bensen
http://www.prairienet.org/~dsb/
From: Pascal Bourguignon
Subject: Re: help me identify error here: beginners question
Date: 
Message-ID: <87skyrpqzo.fsf@thalassa.informatimago.com>
Ravi <···········@gmail.com> writes:

> 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. 

Well, news:comp.lang.scheme would be more indicated, but since these
newbie questions would be the same for Common Lisp...

> Can You please
> help me why following errors occur and what they mean:

Write ALL your operations as (OPERATOR ARGUMENT...)
Again: Write **ALL** your operations as **(** **OPERATOR**  **ARGUMENT**... **)**

Lisp is actually extremely simple.  The only thing you have to do, is 
to always write ALL your operations as:  (  OPERATOR  ARGUMENT...  ) 

There's no syntax, since it's always the same, you always 
write: - an opening parenthesis
       - the operator name
       - the arguments
       - a closing parenthesis.

If you are able to stubbornly always write your operations as (OPERATOR ARGUMENT...)
then you have all the I.Q. needed to write lisp.


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

Yep, you encounter them but you forgot to press on the "ON" button of
your brain.  This is strange, sometimes when encountrering something
new, people just stop thinking...   Try to read and understand these
error messages!

> Warning: invalid arguments
>          (< - (* b b) (* 4 a c) 0)

This is the erroneous expression.

>          (procedure wants: (:real :real &rest :real))

This is guess what?  What the procedure wants.  It wants, a real
number, and then a real number, and them possibly some more real
numbers.  Not very surprizing from <.

The arguments are:
           -             is it a real number? 
           (* b b)       is it a real number?
           (* 4 a c)     is it some more real number?
           0             is it some more real number?

NO!

>          (arguments are: ((proc (:number  &opt :number) :number) :number :number :exact-integer))
           -             is a proedure that takes some numbers and return a number.
           (* b b)       will evaluate to a number (let's hope a real number)
           (* 4 a c)     will evaluate to a number (let's hope a real number)
           0             is an exact integer that can be made into an inexact 
                         real number.

So it clearly and very detailledly says that you passed the procedure - as
argument instead of a number.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Our users will know fear and cower before our software! Ship it!
Ship it and let them flee like the dogs they are!"