chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Re: Read-line fix


From: felix winkelmann
Subject: [Chicken-users] Re: Read-line fix
Date: Tue, 21 Mar 2006 17:32:49 +0100

On 3/20/06, Reed Sheridan <address@hidden> wrote:
> >
> > (pp (with-input-from-string "foo\r" read-line))
> >
> > ==> "foo^@"
>
>
>
> read-line did that before my patch.

Indeed it did. Serves me right.

> I didn't do anything to non-file input.
>  AFAICT, the old behavior of read-line was:
>
> for file input:
> "foo\nmore"         -> "foo"
> "foo\r\nmore"       -> "foo"
> "foo" (end of file) -> "fo"
> "foo\rmore\n"       -> "foo\rmore"
>
>
> for non-file input:
> "foo\nmore"           -> "foo"
> "foo\r\nmore"         -> "foo"
> "foo\r" (end of file) -> "foo\r" (as in your example)
> "foo\rmore"            -> "foomore"
>
> If I understand you correctly, you want readline to terminate a line on \r,
> \n, or \r\n and not include the separator in the result?

Yes.

> This creates
> difficulties for the fast path because fgets doesn't care about \r.
>
> So to deal with \r as I think you intended, we have a few options:
>
> 1. Get rid of the fast path and scan every string for \r, \r\n, and \n in
> Scheme
> 2. Include an extended fgets in C that deals with \r
>  3. Change the specification, which the old implementation didn't come close
> to following anyway.
>
> If I could have my way and break everybody's code in the process, I would
> make the separator a parameter and include it in the results, and add a
> "chomp" function to get rid of separators at the end of a line.
>
> What do you think?

Well, I'd prefer to remove the separator right away. And I must insist
in backwards
compatibility. I admit that the old implementation isn't very good,
but saying that
it didn't come close to the spec is a bit string (the spec is to
meagre for that - it
just says that `read-line' reads a line of input).

What about this: I'll fix the zero-character in non-file input and you implement
an alternative with a parameter, a different name and a chomp function?
(A lame compromise, I know)


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]