[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Proposed extension to DOLIST, DOTIMES
- Subject: Re: Proposed extension to DOLIST, DOTIMES
- From: Guy.Steele at CMU-10A
- Date: Fri ,20 Mar 81 23:57:00 EDT
One is permitted to use RETURN within DOLIST and DOTIMES, and this
is very useful for aborting the iteration. It would be more
useful if one could reliably return a value to look at. This
can be done with RETURN, but the problem is that there is no way to
specify the value if the iteration finishes successfully. Hence
I propose that
(DOLIST (var list retval) . body)
be just like DOLIST, except that if and when all iterations are
completed, the form "retval" is evaluated and its value becomes
the result of the DOLIST (similarly for DOTIMES). If retval is
omitted, () is used (I believe that is what happens now anyway).
(defun first-word-in-string (str) ;spaces separate words
(dotimes (j (string-length str) str)
(when (char= #/space (char j str))
(return (substring str 0 j)))))
This returns the first "word" in a given string. If the string
has no spaces, then the string itself is returned. If one wants
both the word and the index of the space, or () if no space was
found:
(defun first-word-in-string (str)
(dotimes (j (string-length str) (values str ()))
(when (char= #/space (char j str))
(return (substring str 0 j) j))))
--Guy