Well, here is a naive way to do this:
let a []
let b []
let c []
file-open "data.txt"
while [ not file-at-end? ] [
set a lput file-read a
set b lput file-read b
set c lput file-read c
]
file-close
It is assumed that the number of elements in your file will be a multiple of 3. You will have problems if this is not the case.
Edit:
... and here is a much longer, but also more general and reliable way to do this:
to-report read-file-into-list [ filename ]
file-open filename
let xs []
while [ not file-at-end? ] [
set xs lput file-read xs
]
file-close
report xs
end
to-report split-into-n-lists [ n xs ]
let lists n-values n [[]]
while [not empty? xs] [
let items []
repeat n [
if not empty? xs [
set items lput (first xs) items
set xs but-first xs
]
]
foreach (n-values length items [ ? ]) [
set lists replace-item ? lists (lput (item ? items) (item ? lists))
]
]
report lists
end
to setup
let lists split-into-n-lists 3 read-file-into-list "data.txt"
let a item 0 lists
let b item 1 lists
let c item 2 lists
end
source
share