Problem with my sine function
Posted: Thu Aug 23, 2012 11:19 am
Hello, I have been learning Common Lisp only for a few days. I thought I would try to write my own simple program to calculate the sine of a number by going though the Taylor series.
Here is my program:
When I try to compile the sine function I get the error:
Does anyone know what the problem is? 
Here is my program:
Code: Select all
(defun fact (n)
(if (<= n 1)
1
(* n (fact (1- n)))))
(defmacro odd (n)
`(1+ (* ,n 2)))
(defun sine (n &optional (a 3)) ;n is the number, a is the accuracy
(let ((result n))
((dotimes (i a)
(if (mod (1+ i) 2)
(setf result (- result (/ (expt n (odd (1+ i))) (fact (odd 1+ i)))))
(setf result (+ result (/ (expt n (odd (1+ i))) (fact (odd 1+ i))))))))))
Code: Select all
While compiling SINE :
In the form (#1=(DOTIMES (I A)
(IF (MOD # 2)
(SETF RESULT #)
(SETF RESULT
#)))), #1# is not a symbol or lambda expression.
[Condition of type CCL::COMPILE-TIME-PROGRAM-ERROR]
