From ... From: Erik Naggum Subject: Re: how to validate input? Date: 2000/04/19 Message-ID: <3165126075587849@naggum.no>#1/1 X-Deja-AN: 613088530 References: <87wvlv75lf.fsf@inka.de> <87og76fxrx.fsf@inka.de> mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 956142993 27638 195.0.192.66 (19 Apr 2000 11:16:33 GMT) Organization: Naggum Software; vox: +47 8800 8879; fax: +47 8800 8601; http://www.naggum.no User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.5 Mime-Version: 1.0 NNTP-Posting-Date: 19 Apr 2000 11:16:33 GMT Newsgroups: comp.lang.lisp * Friedrich Dominicus | I have written the same with a loop but it looks IMO more ugly. it's quite strange, but people who have been trained to write iteration using tail recursion tend to write the most amazingly ugly loops, and it isn't a question of lack of training in writing loops, it's conceptual. (yet another case of Scheme hurting people.) | (defun get-input () | (let ((line)) | (do ((exit nil)) | (exit line) | (format t "Please give me a number (e for Exit): ") | (setf line (read)) | (if (numberp line) | (progn | (setf exit t) | line) | (when (y-or-n-p "Not a number, really exit?") | (setf exit t) | (setf line nil)))))) (format t "please enter a number: ") (do ((input (read nil nil nil) (read nil nil nil))) ((or (null input) (numberp input)) input) (format t "not a number, try again: ")) I'd use a different input function that read, but that's your call. #:Erik