0

I am calling a simple function i wrote in another function but getting an unexpected error.

I have saved and executed the first equation 'square-x' and then called it in the second fucntion 'sum-of-squares' in a different file.

First function:

(defun square-x (x)
  "gives the square of a number"
  (* x x))

Second function:

(defun sum-of-squares (a b)
  "sums the squares of two values"
  ((+ (square-x a) 
      (square-x b))))

When trying to execute this function the error messages are 'the variable a is defined but never used' and the same for b. But i have used them in the calling of another function. Thanks

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346

1 Answers1

3

You are calling the form (+ (square-x a) (square-x b)) with no arguments. In CL only symbols and lambda forms may be in operator position, not (+ (square-x a) (square-x b))

;; wrong
((+ (square-x a) (square-x b)))

;; correct 
(+ (square-x a) (square-x b))

In Both CLISP an SBCL this is the main ERROR, but I notice SBCL also mentions as a warning that a and b are never used. This is of course because it disregards the code in the wrong operator (+ (square-x a) (square-x b)) completely.

In Scheme, where expressions in operator position is allowed, you would have got Application: not a procedure because the result of (+ (square-x a) (square-x b)), which most likely would be a number, would be called with no arguments as a function.

Sylwester
  • 47,942
  • 4
  • 47
  • 79