[REBOL] Storing/loading object functions
From: knizhnik::garret::ru at: 6-Dec-2003 21:20
GI> Hi Konstantin,
KK>> I am developer of object oriented database for dynamic languages
KK>> (www.garret.ru/~knizhnik/dybase.html)
KK>> Currently it supports PHP, Python and Ruby. Now I am going to develop
KK>> Rebol API for DyBASE.
GI> That's great! I think someone mentioned DyBase here not too long ago.
GI> Christian already answered your question, but please don't hesitate to
GI> ask more questions here. I think a lot of us would be glad to help,
GI> and there are some real gurus here so, if it can be done, someone here
GI> will know how to do it.
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
GI> You may even get a volunteer or two to help you!
GI> --Gregg
--
Best regards,
Konstantin mailto:[knizhnik--garret--ru]