Atomica
Atomica

Reputation: 23

What is the best way to save a hash! block in Rebol?

I am using Rebol2 and would like to persist a HASH! block.

Currently I am converting it to-string then using save.

Is there a better way? For example:

r: make hash! ["one" "two"]

I want to save this to a file, then load it back to r.

Upvotes: 0

Views: 168

Answers (2)

9214
9214

Reputation: 2193

You do that just like with any other value - save, then load.

There are zero benefits in using hash! for persistent storage, by the way. What load gives you back is a plain block! ([make hash! [...]]). Populating hashtable from this loaded data takes more time compared to just loading block!, but gives you faster lookups thereafter.

In other words, you can just:

>> save %database [one two]
>> make hash! load %database
== make hash! [one two]

As described in the tutorial that you linked.

Upvotes: 0

sqlab
sqlab

Reputation: 6436

you are very near your goal. Just use save/all and load

>> r: make hash! ["one" "two"]
== make hash! ["one" "two"]
>> save/all  %htest r
>> r: load %htest
== make hash! ["one" "two"]

If you want the same result in Red you just need one command more

>> r: do load %htest
== make hash! ["one" "two"]

Upvotes: 1

Related Questions