Home   Archive   Permalink


What is mold? Can you give me an example?

posted by:   Totardo       26-Sep-2013/9:37:57-7:00

Mold encloses text in quotes.
write %mold.txt mold "some text"
print read %mold.txt
The write line above is the same as:
write %mold.txt {"some text"}

posted by:   Nick       26-Sep-2013/12:43:25-7:00

The IMHO more important MOLD/ALL (/ALL being a refinement to MOLD) serializes REBOL code and data, so you can save it to disk and load it again:
>> a: make object! [b: make hash! [] c: 67 d: none]
>> mold/all a
== {#[object! [
     b: #[hash![]]
     c: 67
     d: #[none]
>> probe load mold/all a
make object! [
     b: make hash! []
     c: 67
     d: none

posted by:   Henrik       26-Sep-2013/13:36:02-7:00

To add a little to Henrik's example above, you can save and load to a file, for example, like this:
a: make object! [b: make block! [] c: 67 d: none]
write %somedata compress mold/all a
probe load decompress read %somedata

posted by:   Nick       27-Sep-2013/11:10:13-7:00

The example above works in R3. Compressed data is binary, so for R2, you'd need /binary refinements:
write/binary %somedata compress mold/all a
probe load decompress read/binary %somedata
More likely, you'd just do:
write %somedata mold/all a
probe load %somedata

posted by:   Nick       27-Sep-2013/14:53:01-7:00

(That works in both R2 and R3)

posted by:   Nick       27-Sep-2013/14:54:42-7:00