Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Object Sea - Melt and Freeze

 [1/3] 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. :) ] ] ]

 [2/3] from: cybarite:sympatico:ca at: 23-Feb-2002 10:40


Hi Andrew, I have been sitting in the back of the slow class on this Freezing and Melting. Can you show me a usage example or correct what I have been trying or thinking about how to deploy? I want to have a lot of REBOL objects, structures etc and have them persist with all of their complex inter-relationships and then re-instantiate back to the state when I stored them. I want to freeze them with one REBOL command by invoking your function and re-instantiate (melt) them with one REBOL command. Sounds super so far for freezing and melting to do that. Do I have to collect them with something like: customer: make object! [ id: name: address: status: none ] sea: copy [] append sea don-trump: make customer [name: "Donald Trump" id: 1 address: Trump HQ, New York status: 'active] If I do save %MySea.txt Freeze Sea then start a new instance of REBOL and run %freeze.r then do Sea: Melt reduce load %MySea.txt I have a customer instance available but don't have the association with 'don-trump Can I freeze the name-space too (or whatever you would call it)?

 [3/3] from: al:bri:xtra at: 24-Feb-2002 8:49


Mike Myers wrote:
> Can you show me a usage example or correct what I have been trying or
thinking about how to deploy? Here's one Rebol console session:
>> customer: make object! [
[ id: name: address: status: none [ ]
>> sea: make block! 100
== []
>> append Sea make Customer [
[ name: "Donald Trump" [ id: 1 [ address: "Trump HQ, New York." [ status: 'active [ ] == [ make object! [ id: 1 name: "Donald Trump" address: "Trump HQ, New York." status: 'active ...
>> cd %/c/
== %/c/
>> save %/c/MySea.txt freeze sea
And here's another Rebol console session:
>> cd %/c/
== %/c/
>> sea: melt reduce load %/c/MySea.txt
== [ make object! [ id: 1 name: "Donald Trump" address: "Trump HQ, New York." status: 'active ...
>> probe sea/1
make object! [ id: 1 name: "Donald Trump" address: "Trump HQ, New York." status: 'active ]
> I have a customer instance available but don't have the association with
'don-trump
> Can I freeze the name-space too (or whatever you would call it)?
Don't do this:
> append sea don-trump: make customer [name: "Donald Trump" id: 1 address:
Trump HQ, New York status: 'active] in particular, assigning a word "don-trump: " that relates to the object (the "name-space"). That's because Rebol can only have 4096 words in total and a lot of these are used up all ready, and most functions need words to access them. To keep track of the customer objects, it's best to use a block to store customer objects. Like: Customers: make block! 100 until [ ; operator enters customer details. ;eg Customer: make object! [ name: name_details ; from form address: address_details ; from form Id: new_ID_Number ; or similar function. Status: 'action ] append Customers Customer no_more_customers ] append/only Sea Customers ; use /only to append the block! value as a block! I hope that helps! Andrew Martin ICQ: 26227169 http://valley.150m.com/