Loading and saving files
Red also has the save
and load
words, that can be used interchangeably with write
and read
. However, save
and load
are generally used to store more complex data structures, and in particular to store and load Red code. But we already know that in Red, code can be treated as data.
To see for yourself that save
and load
can be used for data, answer question 4 in the Questions section.
The save
word can also be used to write data into a string or binary value.
In particular, if you have a file with data items separated by a space, load
will transform that into a series with the items. Suppose we have a names
file with the following contents:
"John" "Dave" "Jane" "Bob" "Sue" "Sarah" "Mikhail" "Rudolf" "Nenad"
If we use load
to read in that file, we get the following:
;-- see Chapter07/saving-and-loading.red: names: load%names probe names == ["John""Dave""Jane""Bob""Sue" "Sarah""Mikhail""Rudolf""Nenad"] type? names ;== block!
Because code can have a complex structure, you should...