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?
Afficher les réponses par date
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