reflectionrebolrebol3

How should a Rebol-structured data file (which contains no code) be written and read?


If you build up a block structure, convert it to a string with MOLD, and write it to a file like this:

>> write %datafile.dat mold [
    [{Release} 12-Dec-2012]
    [{Conference} [12-Jul-2013 .. 14-Jul-2013]]
]

You can LOAD it back in later. But what about headers? If a file contains code, it is supposed to start with a header like:

rebol [
    title: "Local Area Defringer"
    date: 1-Jun-1957
    file: %defringe.r
    purpose: {
        Stabilize the wide area ignition transcriber
        using a double ganged defringing algorithm.
    }
]

If you are just writing out data and reading it back in, are you expected to have a rebol [] header, and extend it with any properties you want to add? Should you come up with your own myformat [] header concept with your own properties?

Also, given that LOAD does binding, does it make sense to use it for data or is there a different operation?


Solution

  • Rebol data doesn't have to have a header, but is best practice to include one (even if it's just data).

    Some notes:

    Putting this together:

    save/all/header %datafile.dat reduce [next "some" 'data][
        title: "Some Data"
    ]
    
    header: take data: load/header %datafile.dat
    

    To use a header other than Rebol [], you'd need to devise a separate loader/saver.