在Rebol中有更优雅的语法吗?

时间:2009-07-30 18:33:22

标签: persistence rebol

我正在写一篇关于Rebol的Object持久性的教程,但我不确定我的方式是否最好

假设%config.txt包含

a: 1
b: 2

然后我们可以用

加载它
config: construct load %config.txt

要将其保存回文件我使用此

save %config.txt (pick to-block mold config 3)

但我不确定这是在Rebol中执行此操作的最优雅的语法,所以您有其他建议吗?

2 个答案:

答案 0 :(得分:3)

有人会说保存整个物体更优雅。但这会导致编辑文本文件变得不那么容易。 (我假设你可能有人在编辑文本文件)。

保存的简短形式:

save %config.txt mold third config

答案 1 :(得分:2)

或不必要的更短

save %config.txt body-of config

我不认为模具是必要的,如果你塑造它然后它将是一个字符串,你需要加载它两次

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

所以,根本不要使用模具。

相关问题