[REBOL] Object Sea - Work in Progress
From: al::bri::xtra::co::nz at: 21-Feb-2002 19:33
Hi, everyone!
I've been working on storing Rebol objects to a file and retrieving them
again, which I'm calling a "Object Sea" for want of a better phrase or word.
An object sea looks like:
[
make object! [
M: 123
Name: "Sea #1"
O:
make object! [
M: 456
Name: "Sea #2"
O:
make object! [...]
F: none
]
]
make object! [
M: 456
Name: "Sea #2"
O:
make object! [
M: 123
Name: "Sea #1"
O:
make object! [...]
]
F: none
]
make object! [
outside:
make object! [
N: "Antidisestablishmentarianism"
]
]]
Which is basically a block "containing" a number of objects, in this case, 3
objects with one object "outside" the block or sea. When run through my
'Freeze function, this becomes frozen into:
[
make object! [
M: 123
Name: "Sea #1"
O: './2
]
make object! [
M: 456
Name: "Sea #2"
O: './1
F: none
]
make object! [
outside: './4
]
make object! [
N: "Antidisestablishmentarianism"
]]
With objects all inside the block and object "references" replaced with a
path like:
'./2
which mimics the use of the file directories %.. (parent directory) and
%. (containing directory). This block can then be 'save-ed to disk as a
file, then 'load-ed and 'Melt-ed into a object sea.
At the moment, the 'Freeze-ing and 'Melt-ing functions don't work with
function! values, though they do seem to work with other values (except
maybe block! values...). I'm having a little trouble with Rebol/View
crashing, when I uncomment the script lines that are currently commented
out. No doubt, I'm doing something wrong in my script in handling function!
values.
I'm intending to store function! values in object! at the end of the object
sea block, so that the same functions in multiple objects need only have one
function stored in the 'ice version. Then when 'Melt-ed, all objects are
restored to the object sea with only one function, instead of multiple
copies.
Any one got any ideas or suggestions, on what the script code for handling
function! values should be for 'Melt and 'Freeze?
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
-><-
[
Rebol [
Name: 'Sea
Title: "Sea"
File: %Sea.r
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Date: 21/Feb/2002
]
Outrider: make object! [
N: "Antidisestablishmentarianism"
]
; Example object sea.
Sea: reduce [
make object! [
M: 123
Name: "Sea #1"
O: none
;F: func [X [integer!]] [M: M + X]
]
make object! [
M: 456
Name: "Sea #2"
O: none
F: none
]
make object! [
outside: Outrider
]
]
; First and second objects contain each other.
Sea/1/O: Sea/2
Sea/2/O: Sea/1
;Sea/2/F: get in Sea/1 'F
Freeze: function ["Freezes Object Sea" Sea [block!] /Compact] [Path Index] [
foreach Object Sea [
foreach Word next first Object [
any [
;if function? in Object :Word [
; true
; ]
if object? Path: Object/:Word [
set in Object Word make lit-path! reduce [
'.
either found? Index: find Sea Path [
index? Index
] [
append Sea Path
length? Sea
]
]
]
]
]
]
Sea ; At this point, the 'Sea has become ice. :)
]
Melt: function ["Melts Object Ice" Ice [block!]] [Path] [
foreach Object Sea [
foreach word next first Object [
Path: Object/:Word
if all [
path? Path
2 = length? Path
'. = first Path
integer? last Path
] [
set in Object Word pick Ice last Path
]
]
]
Ice ; At this point, the 'Ice has become sea. :)
]
probe Melt probe Freeze Sea
halt
]
-- Attached file included as plaintext by Listar --
-- File: Sea.r
[
Rebol [
Name: 'Sea
Title: "Sea"
File: %Sea.r
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Date: 21/Feb/2002
]
Outrider: make object! [
N: "Antidisestablishmentarianism"
]
; Example object sea.
Sea: reduce [
make object! [
M: 123
Name: "Sea #1"
O: none
;F: func [X [integer!]] [M: M + X]
]
make object! [
M: 456
Name: "Sea #2"
O: none
F: none
]
make object! [
outside: Outrider
]
]
; First and second objects contain each other.
Sea/1/O: Sea/2
Sea/2/O: Sea/1
;Sea/2/F: get in Sea/1 'F
Freeze: function ["Freezes Object Sea" Sea [block!] /Compact] [Path Index] [
foreach Object Sea [
foreach Word next first Object [
any [
;if function? in Object :Word [
; true
; ]
if object? Path: Object/:Word [
set in Object Word make lit-path! reduce [
'.
either found? Index: find Sea Path [
index? Index
] [
append Sea Path
length? Sea
]
]
]
]
]
]
Sea ; At this point, the 'Sea has become ice. :)
]
Melt: function ["Melts Object Ice" Ice [block!]] [Path] [
foreach Object Sea [
foreach word next first Object [
Path: Object/:Word
if all [
path? Path
2 = length? Path
'. = first Path
integer? last Path
] [
set in Object Word pick Ice last Path
]
]
]
Ice ; At this point, the 'Ice has become sea. :)
]
probe Melt probe Freeze probe Sea
halt
]