tags:

views:

74

answers:

2

When I enter the following:

(define (root a b c)
   (/ (+ (-b) (sqrt (- (exp b 2) (* 4 a c)))) (* 2 a)))

and then enter:

(root 3 6 2)

I get a message indicating that the procedure had two arguments but only requires exactly one. What am I doing wrong??? (be nice I am a newbee).

+3  A: 

The exp function doesn't do exponents really, it does something else mathy. (I don't know.)

What you want is usually called pow for "power" but probably isn't defined in your environment, so I suggest you just define your own square method:

(define (square x) (* x x))

And then:

(define (root a b c)
   (/ (+ (- b) (sqrt (- (square b) (* 4 a c)))) (* 2 a)))

Edit: Oh, you'll also have to change a couple spacing issues, like (* 4 a c) instead of (*4 a c), and (- b) instead of (-b). You always have to separate the operator from the operands with spaces.

yjerem
For the curious, `(exp n)` returns [e](http://en.wikipedia.org/wiki/Euler's_number)^n. And Scheme does have a power function, but it's called `expt`
Michael Mrozek
Thank you! This worked.
Skoolpsych2008
Thankyou Michael
yjerem
A: 

The function the error refers to is exp which takes only one argument. The exp function calculates the exponential function, not an exponent. You want expt, which raises a root x to the exponent y:

(expt b 2)

You can also just multiply the number times itself.

I usually keep R5RS or The Scheme Programming Language on hand since these basic functions can be hard to keep straight.

Joel J. Adamson