Джерело:
Common Lisp Tips
Дата публікації:
25/02/2013 03:32
Постійна адреса новини:
http://www.vsinovyny.com/8323836
25/02/2013 03:32 // Common Lisp Tips
The standard explains common semicolon comment style in section 2.4.4.2. Section 2.4.4.2.5 includes this short example showing typical use of one through four semicolons:
;;;; Math Utilities
;;; FIB computes the the Fibonacci function in the traditional
;;; recursive way.
(defun fib (n)
(check-type n integer)
;; At this point we're sure we have an integer argument.
;; Now we can get down to some serious computation.
(cond ((< n 0)
;; Hey, this is just supposed to be a simple example.
;; Did you really expect me to handle the general case?
(error "FIB got ~D as an argument." n))
((< n 2) n) ;fib[0]=0 and fib[1]=1
;; The cheap cases didn't work.
;; Nothing more to do but recurse.
(t (+ (fib (- n 1)) ;The traditional formula
(fib (- n 2)))))) ; is fib[n-1]+fib[n-2].
| « |
Наступна новина з архіву Trying again with with-simple-restart |
Попередня новина з архіву The tree-walkers of CL |
» | |
|
|
||||