1

Just a new defined arccos-function but I don't find the error:

(define (arccos z)
  (atan (
         (/
         (sqrt (-
               1 (expt (cos z) 2)))
         (cos z)))))

May you help me? Error message:

expected a procedure that can be applied to arguments
  given: 1.1447765772467506
  arguments...: [none]
for (arccos 1)
coredump
  • 37,664
  • 5
  • 43
  • 77
snowparrot
  • 299
  • 1
  • 2
  • 11
  • Solved One ( to much here is the right code: (define (arccos z) (atan (/ (sqrt (- 1 (expt (cos z) 2))) (cos z)))) – snowparrot Oct 21 '15 at 16:12
  • I would recommend to indent the code correctly and then check the syntactical correctness. – Rainer Joswig Oct 21 '15 at 16:12
  • 1
    When getting started with a lisp, the practical meaning of this error message is nearly always: "You have too many parens. Remember that `(` is not like `{`. If you don't have a function name after the `(`, you probably don't need the `(`." :) – Greg Hendershott Oct 21 '15 at 17:49
  • 1
    Possible duplicate of ["application: not a procedure" while computing binomial](http://stackoverflow.com/questions/19487959/application-not-a-procedure-while-computing-binomial) – Joshua Taylor Oct 21 '15 at 19:16

2 Answers2

2

The error type is a common one - so here is how to quickly spot where the error is in a program.

Run it in DrRacket. Notice that this expression is colored red:

       (
         (/
          (sqrt (-
                 1 (expt (cos z) 2)))
          (cos z)))

The error message says: "expected a procedure that can be applied to arguments given". The last part implies that Racket expected ( ... ) to be an application of a procedure (function). However the first argument is : (/ ...) and the result of a division is a number.

That is: When you get this error always look at the first expression.

Here the problem is an extra layer of parentheses ( (/ ...) ) should be (/ ...). In other cases use display to print out the result of the first expression in order to see what went wrong.

Note: In can be helpful to use the following indentation convention when dealing with arithmetical operations:

(operation argument1
           argument2
           ...)

In this example:

  (atan (/ (sqrt (- 1
                    (expt (cos z) 2)))
           (cos z))))
soegaard
  • 30,661
  • 4
  • 57
  • 106
1

Try this:

(define (arccos z)
  (atan (/ (sqrt (- 1 (expt (cos z) 2)))
           (cos z))))

There was an unnecessary pair of brackets after atan, also notice that correctly indenting will make this type of errors easier to spot.

Óscar López
  • 232,561
  • 37
  • 312
  • 386