[REBOL] Object Sea - Melt and Freeze
From: al::bri::xtra::co::nz at: 23-Feb-2002 12:20
With thanks to Romano.
make object! [
Magic: '.
Melt-Value: function [Ice [block!] Berg] [Value Path] [
Value: :Berg
if all [
any [
lit-path? :Berg
path? :Berg
]
Magic = first :Berg
] [
Path: :Berg
if all [
2 <= length? :Path
integer? second :Path
] [
Value: pick Ice second :Path
if all [
3 = length? :Path
integer? third :Path
] [
Value: at Value third :Path
]
]
]
:Value
]
set 'Melt function ["Melts Object Ice" Ice [block!]] [Block Object] [
foreach Berg Ice [
switch type?/word :Berg [
block! [
Block: Berg
forall Block [
Block/1: Melt-Value Ice pick Block 1
]
]
object! [
Object: Berg
foreach Word next first Object [
set in Object Word Melt-Value Ice get in Object Word
]
]
]
]
Ice ; At this point, the 'Ice has become sea. :)
]
]
make object! [
Magic: '.
Freeze-Value: function [Sea [block!] Fish] [Path Value Index] [
either any [
function? :Fish
object? :Fish
series? :Fish
] [
Path: make lit-path! reduce [Magic]
Value: either series? :Fish [head :Fish] [:Fish]
either found? Index: find/case/last Sea :Value [
Index: index? Index
] [
append Sea :Value
Index: length? Sea
]
append :Path Index
if series? :Fish [
append :Path index? Fish
]
:Path
] [
:Fish
]
]
set 'Freeze function ["Freezes Object Sea" Sea [block!]] [Block Object]
[
foreach Fish Sea [
switch type?/word :Fish [
block! [
Block: Fish
forall Block [
Block/1: Freeze-Value Sea pick Block 1
]
]
object! [
Object: Fish
foreach Word next first Object [
set in Object Word Freeze-Value Sea get in Object
Word
]
]
]
]
Sea ; At this point, the 'Sea has become ice. :)
]
]
They're used with an object sea like:
Sea: Melt reduce load %MySea.txt
; Sea is a block with lots of objects and blocks in it.
save %MySea.txt Freeze Sea
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
-><-
-- Attached file included as plaintext by Listar --
-- File: Melt.r
[
Rebol [
Name: 'Melt
Title: "Melt"
File: %"Melt.r"
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Date: 23/Feb/2002
Acknowledgements: "Romano Paolo Tenca"
]
make object! [
Magic: '.
Melt-Value: function [Ice [block!] Berg] [Value Path] [
Value: :Berg
if all [
any [
lit-path? :Berg
path? :Berg
]
Magic = first :Berg
] [
Path: :Berg
if all [
2 <= length? :Path
integer? second :Path
] [
Value: pick Ice second :Path
if all [
3 = length? :Path
integer? third :Path
] [
Value: at Value third :Path
]
]
]
:Value
]
set 'Melt function ["Melts Object Ice" Ice [block!]] [Block Object] [
foreach Berg Ice [
switch type?/word :Berg [
block! [
Block: Berg
forall Block [
Block/1: Melt-Value Ice pick Block 1
]
]
object! [
Object: Berg
foreach Word next first Object [
set in Object Word Melt-Value Ice get in Object Word
]
]
]
]
Ice ; At this point, the 'Ice has become sea. :)
]
]
]
-- Attached file included as plaintext by Listar --
-- File: Freeze.r
[
Rebol [
Name: 'Freeze
Title: "Freeze"
File: %"Freeze.r"
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Date: 23/Feb/2002
Acknowledgements: "Romano Paolo Tenca"
]
make object! [
Magic: '.
Freeze-Value: function [Sea [block!] Fish] [Path Value Index] [
either any [
function? :Fish
object? :Fish
series? :Fish
] [
Path: make lit-path! reduce [Magic]
Value: either series? :Fish [head :Fish] [:Fish]
either found? Index: find/case/last Sea :Value [
Index: index? Index
] [
append Sea :Value
Index: length? Sea
]
append :Path Index
if series? :Fish [
append :Path index? Fish
]
:Path
] [
:Fish
]
]
set 'Freeze function ["Freezes Object Sea" Sea [block!]] [Block Object] [
foreach Fish Sea [
switch type?/word :Fish [
block! [
Block: Fish
forall Block [
Block/1: Freeze-Value Sea pick Block 1
]
]
object! [
Object: Fish
foreach Word next first Object [
set in Object Word Freeze-Value Sea get in Object Word
]
]
]
]
Sea ; At this point, the 'Sea has become ice. :)
]
]
]