Is there a more elegant syntax to do this in Rebol?
-
05-07-2019 - |
Question
I'm writing a tutorial on Rebol's Object persistence but I'm not sure if my way is the best
suppose %config.txt contains
a: 1
b: 2
We can then load it with
config: construct load %config.txt
To save it back to file I use this
save %config.txt (pick to-block mold config 3)
But I'm not sure this is the most elegant syntax to do this in Rebol so do you have another suggestion ?
Solution
Some would say its more elegant to save the entire object. But that would lead to a less easy to edit text file. (I assume you may have humans editing the text file).
A shorter form of your save:
save %config.txt mold third config
OTHER TIPS
or unnecessarily shorter
save %config.txt body-of config
I don't think mold is necessary, if you mold it then it will be a string and you will need to load it twice
save %config.txt mold third config
t: load %config.txt
? t
>> T is a string of value: {[a: 1 b: 2]} ;you need to load this string to make it a block
t: load load %config.txt
? t
>> T is a block of value: [a: 1 b: "x"] ;so t can be used to construct an object
So, simply don't use mold.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow