views:

92

answers:

2

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 ?

+2  A: 

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

+1  A: 

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.

endo64