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

[REBOL] Re: Object "Serialization"

From: agem:crosswinds at: 23-Feb-2001 0:30

>>>>>>>>>>>>>>>>>> Ursprüngliche Nachricht <<<<<<<<<<<<<<<<<<
Am 22.02.01, 23:32:53, schrieb "GS Jones" <[gjones05--mail--orion--org]> zum Thema [REBOL] Re: Object "Serialization":
> > > > In a separate thread, a question was asked about serialization of > > > > objects by Sharriff Aina. I had a similar question in mind and > was > > > > hoping for an answer. Since the thread had gotten a bit off > topic, > > I'm > > > > reposting essentially the same question in this separate thread. > > > > > > > > To date, when I want to save an object, I've been using 'save. > Then > > > > when I need the object back, I use 'read and then 'do the object. > > > > > > > > For example: > > > > > > > > data: make object! [ > > > > name: "Joe" > > > > ] > > > > > > > > save %my-object.r data > > > > > > > > ;... later i need the object ... > > > > data: read %my-object.r > > > > data: do data > > > > print data/name > > > > > > use 'load instead of 'read? Then you don't need to 'do the 'data ... > > > -pekr- > > > > Thanks, that is a good point! > > Scott > Actually, when I tried it, simply using 'load did not re-initialize
the
> object (unless I am missing some additional subtle point). I played > with several additional variations, with the same conclusions. So I > guess the way I've been doing it will have to be good enough. It
still
> seems as though there should be a more seemless and coherent way to > serialize the object.
data: do %my-object.r before that you have like
>> a: [make object! []]
== [make object! []]
>> a/1
== make
>> a/2
== object! So load gives »source«, do »compiles« it. Note 'save of strings has some bugs before last /core-experimental, specially with »{». do not:
>> mold "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{"
== {{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{}}
>> load mold
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{ ** Syntax Error: Invalid string -- {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{}. ** Where: (line 1) {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{} because you have to balance »{» or escape it, and there is no escaped »{» in old rebols. /core 2.4.40 does it ok:
>> mold "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{"
== {^{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^^^{^}} also
>> mold %""
== "%"
>> load mold %""
** Syntax Error: Invalid file -- % ** Near: (line 1) % and pathes have problems
>> a: first [this/that]
== this/that
>> mold a
** Script Error: this has no value ** Near: mold a because they get evaluatet by mold. Don't know if someone want to save pathes? Then, 'save is similar to copy/deep, so if you have two references to the same object, there are two seperate objects after 'do . And of course if you rely on contexts (hand-made bind), this will not save correctly. Knowing this, 'save / 'do is very handy, don't know of a better way. (hope i have mentioned all?) But, some while ago someone said he has written a serialisation which handles some of this problems and will post it if someone asks? Volker