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

[REBOL] Re: Rebol pickling recipes ?

From: al:bri:xtra at: 4-Oct-2002 20:13

Jason wrote:
> ...I am wondering how to 'pickle' Rebol objects?
I've got two functions that work with the older Rebol releases, that flatten and "restore" an object "sea". They're called 'Freeze and 'Melt. They correctly save and restore cyclic or net-like Rebol data structures. I haven't yet updated them for the latest Rebol beta versions. Andrew Martin ICQ: 26227169 http://valley.150m.com/ -><- -- 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] Web: http://valley.150m.com Date: 3/July/2002 Version: 1.0.0 Purpose: {Freezes an object sea.} Category: [util db file 5] Acknowledgements: "Romano Paolo Tenca" ] make object! [ Magic: '. ; This must be the same as the 'Melt function! Find-Same: func [Series [series!] Value [any-type!]] [ while [ all [ found? Series: find/only/case Series :Value not same? first Series :Value ] ][ Series: next Series ] Series ] Freeze-Value: function [Sea [block!] Fish] [Path Value Index] [ if all [ not lit-path? :Fish not path? :Fish any [ function? :Fish object? :Fish series? :Fish ] ] [ Path: make path! reduce [Magic] Value: either series? :Fish [head :Fish] [:Fish] either found? Index: Find-Same Sea :Value [ Index: index? Index ] [ append/only Sea :Value Index: length? Sea ] append :Path Index if all [ series? :Fish 1 < Index: index? Fish ] [ append/only :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. :) ] ] -- 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] Web: http://valley.150m.com Date: 3/July/2002/21:35 Version: 1.0.1 Purpose: {Melts object ice into fluid Rebol script.} Category: [util script file db 5] Acknowledgements: "Romano Paolo Tenca" ] make object! [ Magic: '. ; This must be the same as the 'Freeze function! Melt-Value: function [Ice [block!] Path] [Value] [ Value: :Path if all [ path? :Path Magic = first :Path 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!]] [Rule Value] [ parse Ice Rule: [ any [ Value: path! ( Value/1: Melt-Value Ice Value/1 ) | into Rule | any-type! ] end ] Ice ; At this point, the 'Ice has become sea. :) ] ]