Taking exponent of a number
Posted: Thu Sep 02, 2010 10:16 pm
I am trying to make a function to take the yth power of number n.
That is what I have now. Everytime I run the, the only output is whatever I enter for x, twice. Ex.
(xp 2 3) should print 8. Instead it just prints
2
2
(xp 10 2) should print 100. Instead it just prints
10
10
(xp 100 100) should print a huge number. Instead it just prints
100
100
Why is this?
Code: Select all
(defun xp (x y)
(loop while (> 1 y) do
(setf x (* x x))
(setf y (- y 1))) (print x))
(xp 2 3) should print 8. Instead it just prints
2
2
(xp 10 2) should print 100. Instead it just prints
10
10
(xp 100 100) should print a huge number. Instead it just prints
100
100
Why is this?