(def readline ((o s (stdin)))
(aif (readc s)
(string
(accum a
(xloop (c it)
(if (is c #\return)
(if (is (peekc s) #\newline)
(readc s))
(is c #\newline)
nil
(do (a c)
(aif (readc s)
(next it)))))))))
This version of readline fixes a bug in arc3.1 that reads empty lines incorrectly, and extends the function to also accept CRLF line endings (which is useful for some Internet protocols):
arc> (fromstring "header one\r\nheader two\r\n\r\nhello\nthere\n"
(drain (readline)))
("header one" "header two" "" "hello" "there")This hack depends on arc3.1 and xloop0.
Using the hackinator:
$ hack \
ycombinator.com/arc/arc3.1.tar \
awwx.ws/xloop0.arc \
awwx.ws/readline1.arcSame as Arc.