From ... From: Erik Naggum Subject: Re: Newbie asking for help Date: 2000/06/22 Message-ID: <3170694191065750@naggum.no>#1/1 X-Deja-AN: 637775378 References: <8iti9v$d19$1@nnrp1.deja.com> <8itmcl$g6q$1@nnrp1.deja.com> mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 961706295 16278 195.0.192.66 (22 Jun 2000 20:38:15 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.6 Mime-Version: 1.0 NNTP-Posting-Date: 22 Jun 2000 20:38:15 GMT Newsgroups: comp.lang.lisp * Lieven Marchand | This isn't meant to reopen the great LOOP flame war but one way of | doing it is: | | (with-open-file (ifile "key.html" :direction :input) | (loop for line = (read-line ifile nil) | while line | counting 1)) Simply using while (read-line ifile nil nil) seems even more compact. However, I have this negative gut reaction to wanton waste, as in effectively allocating as many strings as there are lines for no good reason, just exercising the garbage collector, so while we're at it, how about (loop for char = (read-char ifile nil nil) while char count (char= char #\newline)) Note that read-line will return nil on an empty file, but the data leading up to the end-of-file if no newline intervened and then nil on the next call, effectively counting a non-empty file containing no newlines as having one line. This may be relevant. | (loop for line being each line of ifile | count 1) Elegant. #:Erik -- If this is not what you expected, please alter your expectations.