Advertisement
4da

read strings from file

4da
Jan 22nd, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. \* read a string from stream (EOF and #10 are delimitters) *\
  2. (define read-string
  3.   {(stream in)--> string}
  4.   Stream -> (let Byte (read-byte Stream)
  5.           (if (or (= Byte -1) (= Byte 10))
  6.           ""
  7.           (cn (n->string Byte) (read-string-from-file Stream)))))
  8.  
  9. \* read list of strings from stream *\
  10. (define read-strings-from-stream
  11.   {(stream in) --> (list string)}
  12.   Stream -> (let Str (read-string-from-file Stream)
  13.           (if (= Str "")
  14.           []
  15.           [ Str | (read-text-stream Stream) ])))
  16.  
  17. \* read list of strings from file *\
  18. (define read-text-file
  19.   {string --> (list string)}
  20.   Path -> (read-strings-from-stream (open file Path in)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement