a version of readline that accepts both lf and crlf endings

(def readline ((o s (stdin)))
  (aif (readc s)
     (accum a
       (xloop (c it)
         (if (is c #\return)
              (if (is (peekc s) #\newline)
                   (readc s))
             (is c #\newline)
              (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.

Get this hack

Using the hackinator:

$ hack \ \ \


Same as Arc.

Contact me

Twitter: awwx
Email: andrew.wilcox [at]