Newsgroups: comp.lang.lisp
From: p...@acm.org (Pierre R. Mai)
Date: 2000/06/22
Subject: Re: Newbie asking for help
The Glauber <theglau...@my-deja.com> writes: I think you should report that as a bug to the implementors of CLISP. > In article <8iti9v$d1...@nnrp1.deja.com>, glauber wrote: > [...] > > It doesn't work (it just hangs, so i think it's stuck in the loop). I > OK. Using TRACE, i found that read-line wasn't returning nil, but The HyperSpec is quite clear in that the default value for eof-value should be nil, and therefore (read-line stream nil) should always return nil at the end of file. At least that is my reading of the standard. BTW: I very often supply the eof-value explicitly, for reasons of > (with-open-file (ifile "key.html" :direction :input) OK, you asked for it ;) > (setf nlines 0) > (loop > (if (read-line ifile nil nil) > (setf nlines (+ 1 nlines)) > (return (print nlines))))) > So, i plod along, undaunted... - The most obviously mistake lies in your use of setf to establish a - The variable names are distinctly unlispy: Since CL (and Scheme) - Wrap your code fragment in a function definition, and you get a - While working with low-level looping constructs can be instructive, - Don't print the result yourself, since the surrounding code or the - Use documentation strings to document your functions Given all of the above, your function might be written like this (defun count-lines-in-file (filename) Or, using the extended loop facility: (defun count-lines-in-file (filename) Or, using simple loop, like you did: (defun count-lines-in-file (filename) Beware that all of the code is untested, though ;) Regs, Pierre. -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||