[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

read-line



As Norman reported, READ-LINE returns a string for one "line".  The
default method is to do READC's until a #\NEWLINE is encountered, but
this is handled more efficiently by streams open on files or
terminals.  If you want to read objects in an input line, try

(DEFINE (READ-LINE-OF-OBJECTS INPUT-STREAM)
  (LET ((STREAM (STRING->INPUT-STREAM (READ-LINE INPUT-STREAM))))
    (ITERATE LOOP ((L '()))
      (LET ((OBJ (READ STREAM)))
	(COND ((EOF? OBJ) (REVERSE! L))
	      (T (LOOP (CONS OBJ L))))))))

With this definition, if the line has incomplete expressions, you'll get
an "end of file in read" error (shouldn't that be "end of stream?" -
sigh).  Sometime this summer you'll be able to do other things with such
conditions using BIND or CONDITION-BIND (like continue reading?) but not
yet.  As for continuing if the line ends a certain way, you could easily
write a loop which simply inspects the string returned by READ-LINE,
etc.

I agree that this isn't terrific style, but that's a subject for another
debate in which I'm unwilling to involve myself at this point.