Is it there a better way to read a file in a list ?
Posted: Fri Feb 18, 2005 10:52 am
I'd like to read a file in a list, having each line as a separate string.
I've tried this, but it seems to me a little clumsy.
Is it there a better way ?
Regards
Maurizio
I've tried this, but it seems to me a little clumsy.
Is it there a better way ?
Regards
Maurizio
Code: Select all
(define (read-my-file)
(set 'lst '())
(set 'in-file (open "myfile.txt" "read"))
(while (read-line in-file)
(set 'lst (append lst (list (current-line)))))
(close in-file)
lst)