[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
&rest [discussion] replacement/addition
- To: gooch@mcc.com
- Subject: &rest [discussion] replacement/addition
- From: Barry Margolin <barmar@Think.COM>
- Date: Fri, 8 Apr 88 18:29 EDT
- Cc: edsel!jonl%labrea.Stanford.EDU@mcc.com, common-lisp%sail.stanford.edu@mcc.com, spe%spice.cs.cmu.edu@mcc.com, ELIOT%cs.umass.edu@mcc.com, gz%spt.entity.com@mcc.com
- In-reply-to: <880408160418.1.GOOCH@CHANGABANG.CAD.MCC.COM>
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)
)))