[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
&rest [discussion] replacement/addition
I noticed you didn't try the following version. This is identical to
the version you included in your message, except that it takes the
previous words as a single argument rather than as an &REST argument.
One definite advantage of this version is that it won't exceed
CALL-ARGUMENTS-LIMIT if it recurses deeply.
(defun anagrams (string &optional previous-words)
(let ((chars (unused-characters string previous-words)))
(if chars
;; there are unused characters left
(let ((new-word (find-word chars)))
(when new-word
;; found a new word
(anagrams string (cons new-word previous-words))
;; if no new word could be found, just return
))
;; all characters are used by previous-words, we have a weiner
(save-and/or-print-anagram string previous-words)
)))