From: Kaz Kylheku <kaz@as...>  20030714 21:24:57

On Mon, 14 Jul 2003, lin8080 wrote: > Now, when I type in (rechne (sin 30)) it returns some numbers in the way > like complex numbers are shown. And I think there is something going > wrong ... The input to the trigonometric functions in Lisp, and many other programming languages, is expressed in radians, rather than degrees. It is an instant ``red flag'' when someone is trying to take the sine of 30 in a programming example that doesn't work. :) Radians are units based on the idea that the radius of a circle represents one unit going around the circle. Hence there are (* 2 pi) radians to 360 degrees, and 30 degrees is (/ pi 6) radians or about 0.524. The reason some numbers coming out of your program are shown in complex notation is because they really *are* complex. The value of (sin 30) is approx 0.988. The square root of that is a negative number. In some programming languages, taking the square root of a negative number triggers an error. Lisp is different and better; it produces a complex number. This is one of the advantages of dynamic typing. Dynamic typing allows a function to compute an object whose type is based on the properties of its inputs; the restriction that a function must have a rigid, compiletime ``return type'' is not imposed. > Here is the code: > > (setq rechen (makearray '(9 3))) This works as casual use in CLISP and other Lisp implementations, but in serious Lisp programs you should use DEFVAR, DEFPARAMETER for defining global variables. It's not welldefined behavior to SETQ or SETF a symbol which has no previously defined variable binding. Also, unless you are working in your own package it's probably a good idea to name global variables with a leading and trailing asterisk: (defvar *rechen* (makearray '(9 3))) Use LET for local variables: (let ((x (* zahl zahl))) (setf (aref *rechen* 0 1) x)) But this really isn't any clearer than: (setf (aref *rechen 0 1) (* zahl zahl)) 