Rebol Config/INI File Difficulty
[1/4] from: rsnell:webtrends at: 2-Aug-2000 9:50
I'm trying to do something that Rebol should handle so
easily but it's taking me way too much time so I could
use a couple of tips to get going.
I have a small DB that I usually (in C++) construct
by using an INI (Win32) file - where each section is
a new record and it has some number of keys/values.
I now want to change the format of this INI file so
that it takes full advantage of the Rebol do/load and
save mechanisms.
An example of the DB - this is what the file (myp.dat) should look like
after it is built (it doesn't exist initially):
myprops: [
db [
"item1" [x1 "x1" y1 "y1"]
"item2" [x2 "x2" y2 "y2"]
]
other ["junk"
]
]
Simple enough. So what I want is to use 'do to bind myprops
so I can directly use it and then use 'save to save the block
after modification. I'm just not sure the best way to do this
kind of thing because 'save won't place the myprops: assignment
in the file.
either (exists? %myp.dat) [do %myp.dat] [myp: [db ["item1" [...] "item2"
[...]] other[]]]
probe myp/db
; modify myp/db as needed
save/header %myp.dat myprops []
The problem is the result file just contains the db [] and other [] blocks.
I can't get myprops: into the file.
That would be fine if I could assign myprops to the result of the 'do or
'load
like:
myprops: [do %myp.dat]
but I don't know how to make that work (get Rebol to 'do and place the
result in the block - not to put the literals in the block).
Any ideas? How are you guys accomplishing similar things?
TIA,
Rodney
[2/4] from: agem:crosswinds at: 2-Aug-2000 22:50
>> b: [ 1 2 3 ] save/header %t.r compose/deep[a: [(b)]] []
>> print read %t.r
REBOL []
a: [1 2 3]
[3/4] from: rsnell:webtrends at: 3-Aug-2000 9:24
Thanks for the 'compose lesson. I've never had to use it.
I can get something close to what I want, but I still am having
trouble getting the following to work.
Here is one file %in.dat:
REBOL []
[
ss
[
item1 "hello"
item2 "goodbye"
]
other
[
n "bad"
]
]
Fine. Now a console session....
>> sprops: do %in.dat
== [
ss
[
item1 "hello"
item2 "goodbye"
]
other
[
n "bad"
]
]
>>save/header %out.dat sprops []
Here is what %out.dat then contains:
REBOL []
ss
[
item1 "hello"
item2 "goodbye"
]
other
[
n "bad"
]
Not what I want. I want (expect) to see exactly what is in
the file %in.dat. So I say, OK, use compose/deep to enclose
the thing in a block. The following:
>>save/header %out.dat compose/deep [(sprops)] []
gives the same %out.dat as before. And this:
>>save/header %out.dat compose/deep [[(sprops)]] []
makes %out.dat look like the following:
REBOL []
[[
ss
[
item1 "hello"
item2 "goodbye"
]
other
[
n "bad"
]]]
As you can see there are is now an extra enclosing block instead of just
one!!!
How do I save sprops, which has the exact form I want, to %out.dat so it
looks exactly like %in.dat???
TIA,
Rodney
[4/4] from: agem:crosswinds at: 4-Aug-2000 0:08
very confusing. maybe a bug?! ;-) some while later..
if not, note 'save is paired with 'load .
in the saved file there are no brackets around, as in
save/header %out.dat sprops []
but after loading you have all in a block again.
so you can do
sprops: LOAD %in.dat
this seems to work ok too:
save/header %out.dat compose/deep [ sprops: [(sprops)] ] []
instead of:
save/header %out.dat compose/deep [ [(sprops)] ] []
evil magic :)
you wanted a "sprops:" in your save for doing, hopefully?
[REBOL [title: "the save/load - demo"]
pdo: func [a] [print ">>>" probe a print "===" do a]
write %in.dat {
REBOL []
sprops: [ 1 [ a ] 2 ]
}
pdo[print read %in.dat]
pdo [sprops: do %in.dat
?? sprops]
pdo [save/header %out.dat sprops []
print read %out.dat
print "---"
probe load %out.dat
]
pdo [save/header %out.dat compose/deep [sprops: [(sprops)]] []
print read %out.dat
print "---"
probe load %out.dat
]
]
--- [rsnell--webtrends--com] wrote at 3-Aug-2000/9:24:35-7:00
> Thanks for the 'compose lesson. I've never had to use it.
> I can get something close to what I want, but I still am having
<<quoted lines omitted: 61>>
> TIA,
> Rodney
Volker
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted