From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!news2.kpn.net!news.kpn.net!nslave.kpnqwest.net!nloc2.kpnqwest.net!nloc.kpnqwest.net!nmaster.kpnqwest.net!nreader3.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: [LISP Beginner] Recursion Problem References: <9sm17o$14csis$1@ID-39503.news.dfncis.de> Mail-Copies-To: never From: Erik Naggum Message-ID: <3214496638428058@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 25 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 11 Nov 2001 19:44:00 GMT X-Complaints-To: newsmaster@Norway.EU.net X-Trace: nreader3.kpnqwest.net 1005507840 193.71.66.49 (Sun, 11 Nov 2001 20:44:00 MET) NNTP-Posting-Date: Sun, 11 Nov 2001 20:44:00 MET Xref: archiver1.google.com comp.lang.lisp:19596 * Ingo Rohlfs | What I'm doing wrong? Basically, using recursion for this problem, which is only confusing yourself and wasting a lot of space. This is a shot with a _much_ more powerful technique, iteration, using loop, which is very good for this kind of problem. (Some would tell you that since it is possible to get lost in loop, you should not even try it. Ignore them and trust your own ability to recognize when you are about to get lost. The same is true of recursion, when you get lost in it, it is unsuited for the task. Some people, especially those overexposed to Scheme, never seem to grasp this.) (defun get-elements (sequence) (loop for start = 0 then (1+ end) for end = (position #\Space sequence :start start) collect (subseq sequence start end) until (not end))) /// -- Norway is now run by a priest from the fundamentalist Christian People's Party, the fifth largest party representing one eighth of the electorate. -- Carrying a Swiss Army pocket knife in Oslo, Norway, is a criminal offense.