User:Eriksiers/Alternate CLISP exponentiation: Difference between revisions
User:Eriksiers/Alternate CLISP exponentiation (view source)
Revision as of 19:51, 13 July 2013
, 10 years agono edit summary
(created) |
No edit summary |
||
Line 1:
This is a better example of exponent (it doesn't solve for negatives however so I will leave in tact the other example):
<lang lisp>
(defun ^ (a b)
(let ((r 1))
(dotimes (x b r)
(setf r (* r a)))))
</lang>
I wrote this while reading the first few chapters of [http://www.gigamonkeys.com/book/ Practical Common Lisp]. (I'm about halfway through chapter 4 right now.) It ''seems'' to work -- at least for me, using [[CLISP]] -- and I ''think'' it might be a better version than the "real" solution provided at [[Exponentiation operator#Common Lisp]], but I'm still way too green to know for sure. (This version can handle negative values of '''b''', whereas that version can't -- I think.)
|