I'm trying to create a list of the contents within a file, problem is that the list is flat, it does not include the newlines (\r\n).
#lang racket
(define my-list '())
(define (read-all-file file-to-read)
(for/list ([i (file->lines file-to-read)]) (
set! my-list (foldr cons (list i) my-list))))
my-list
now my output is for example:
"lalala" "lalalall" "lalal"
instead of:
"lalala"
"lalalall"
"lalal"
Does anyone know how I could fix this? I thought the way I was doing it would have worked.. this is strange :/
The list is fine, it's just a matter of how you display its elements. If you want to show them with newlines, do as follows:
Another alternative would be:
Either way, it works as expected: