User Tools



  • dotimes (var count-form [result-form]) declaration* {tag | statement}*result*

Arguments and Values


dotimes iterates over a series of integers.


An implicit block named nil surrounds dotimes.






(dotimes (temp-one 10 temp-one)) → 10 (defparameter *temp-two* 0) → 0 (dotimes (*temp-one* 10 t) (incf *temp-two*)) → T *temp-two* → 10

Here is an example of the use of dotimes in processing strings. We define a function which returns tue if the specified subsequence of the string is a palindrome (reads the same forwards and backwards).

(defun palindromep (string &optional (start 0) (end (length string))) (dotimes (k (floor (- end start) 2) t) (unless (char-equal (char string (+ start k)) (char string (- end k 1))) (return nil))))


(palindromep "Able was I ere I saw Elba")


(defvar *palindrome-1* "A man, a plan, a canal--Panama!")


(palindromep *palindrome-1*)


(remove-if-not #'alpha-char-p *palindrome-1*) ; Remove punctuation.


(palindromep (remove-if-not #'alpha-char-p *palindrome-1*))


(defvar *palindrome-2* "Unremarkable was I ere I saw Elba Kramer, nu?")


(palindromep (remove-if-not #'alpha-char-p *palindrome-2*))


(defvar *palindrome-3* "A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal--Panama!")


(palindromep (remove-if-not #'alpha-char-p *palindrome-3*))


Side Effects


Affected By


Exceptional Situations


See Also

