Arc Forumnew | comments | leaders | submitlogin
Bug in readline
2 points by aw 3428 days ago | 8 comments
Contents of file "foo":

  one
  two
  
  three
Calling readline in Arc 3.1:

  arc> (w/infile s "foo" (drain (readline s)))
  ("one" "two" "\nthree")


2 points by rocketnia 3428 days ago | link

Well, this behavior at least guarantees that any string readline returns will be at least one character long. You can [coerce _ 'cons] the result without worrying that you'll confuse the EOF nil with an empty line.

Maybe readline was designed under the idea that Arc strings would be indistinguishable from lists of characters?

-----

1 point by aw 3428 days ago | link

Check for nil before coercing to cons.

-----

1 point by rocketnia 3428 days ago | link

With the fix, I have to do that. Without the fix, I can keep my code brief. For what it's worth, I like the fix better, but then I don't expect to write (aif (coerce (readline) 'cons) ...) much either.

-----

1 point by akkartik 3428 days ago | link

It seems documented at least.

"An initial newline does not terminate the input and appears in the output." http://arcfn.com/doc/io.html#readline

-----

3 points by aw 3428 days ago | link

Better to fix bugs than document them.

-----

1 point by akkartik 3428 days ago | link

Absolutely.

-----

2 points by aw 3428 days ago | link

And a fix: http://awwx.ws/readline

-----

3 points by aw 3403 days ago | link

Updated to accept both LF and CRLF line endings, useful for Internet protocols like HTTP which use CRLF.

-----