[gambit-list] read-line max-length

Marc Feeley feeley at iro.umontreal.ca
Wed Nov 9 07:43:08 EST 2011


On 2011-11-09, at 5:59 AM, Vok Vojwo wrote:

> The documentation for read-line function is a bit vague about the
> max-length parameter. Is the delimiter character included in
> max-length? And how about if the delimiter is not included in the
> returned string?

The max-length is really the maximum number of characters that are *read*.  The removal of the separator from the end of the string of characters read happens after reading the characters.  Here's an example:

> (define (f is n)
    (call-with-input-string "1\n234\n56"
      (lambda (p)
        (let ((x (read-line p #\newline is n)))
          (cons x (read-line p #f))))))
> (f #f 0)
("" . "1\n234\n56")
> (f #t 0)
("" . "1\n234\n56")
> (f #f 1)
("1" . "\n234\n56")
> (f #t 1)
("1" . "\n234\n56")
> (f #f 2)
("1" . "234\n56")
> (f #t 2)
("1\n" . "234\n56")

Marc




More information about the Gambit-list mailing list