I was about to say I found a nice way, but the
following leads to a mold bug, which I mention in
previous email:

>> prototype: make object! [a: 23 class: none do [class: self]]

>> o: make prototype [a: 42]
>> o/class/a
== 23

>> o: make prototype [a: 83]
>> o/class/a
== 23
>> o/a
== 83

So you could iterate through all your objects, collecting
a list of "classes" (eg. reference to prototype), then,
save those "base class" objects, including the functions.
Other, derived objects should have the functions clipped away.

We're assuming that they are all just copies of the
prototype's functions anyway..

That works as long as the derived objects do not modify/redefine
the inherited functions, of course.

After reading Volker's answer I think he is right about
using a string for the class name, for serialisation to db.

Anton.

> So I have once again to ask for a help.
> Unlike all other languages with OO extensions I have deal before, in
> Rebol there are completely no classes - objects are used as
> prototypes to create other objects. Certainly it is very flexible
> approach and in most situation programmer see no difference between
> using class or prototype object.
> 
> But to be able to store and load objects from the database,
> I need to store/load not only object values but also objet functions
> (which actually are treated as normal object fields with function
> value). I have never faced with this problem before (in PHP, Python or
> Ruby) API, because it was always assumed that application itself 
> keeps method
> definition. And if method definition is changed it is likely to be
> changed for all objects of this class and not only for newly created
> objects.
> 
> But in Rebol there is no class. And looks like there is no way to find
> out prototype object for the particular object instance.
> So it seems to me that the only possible solution in Rebol is to store
> functions inside database. So my questions are
> 
> 1. May be I missed something and there is some other way of setting
> object functions for loaded persistent object?
> 2. How it is possible to store function? It seems to be two possible
> solutions: represent it as series or convert it to string.
> I do not know how to implement any of them:
> 
> >> probe :f
> func [][var3: now/time]
> >> to-string :f
> == "?function?"
> >> first :f
> == []
> >> second :f
> == [var3: now/time]
> >> block? :f
> == false
> >> series? :f
> == false
> 
> So to-string function returns only "?function?" string and
> although it is possible to apply to function first, second,... it is
> itself not a block. So is possible to convert function to block and
> visa versa?
> 
> 3. If I store object function as string or some other way, how can I
> restore it? If I apply "do" to string containing function body, then I
> will get function. But...it will not be bounded to the context of the
> object - it will not be able to access instance variables.
> So how can I dynamically create object function?
> 
> 4. And one more question - is there some kind of weak references in
> Rebol?
> 
> A lot of thanks in advance
> Konstantin

> -- 
> Best regards,
>  Konstantin                            mailto:[EMAIL PROTECTED]

-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to