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

Creation of object with unknown structure

 [1/5] from: knizhnik::garret::ru at: 6-Dec-2003 14:15


Hello, I am developer of object oriented database for dynamic languages (www.garret.ru/~knizhnik/dybase.html) Currently it supports PHP, Python and Ruby. Now I am going to develop Rebol API for DyBASE. I read Rebol manual but some questions are still not clear for me. Can some Rebol guru suggest me the best way of dynamic instantiation of object (so that structure of the object is not known at compile time)? For example I have block containing field names and values: ["x" 1 "y" 2 "z" 3] I want to construct object with these fields, so that result will be the same as after creating object using "make": obj: make object! [x: 1 y: 2 z: 3] So the question is actually how can I construct block which contains variable assignments. -- Thanks in advance, Konstantin mailto:[knizhnik--garret--ru]

 [2/5] from: chris:langreiter at: 6-Dec-2003 16:37


> I am developer of object oriented database for dynamic languages > (www.garret.ru/~knizhnik/dybase.html) > Currently it supports PHP, Python and Ruby. Now I am going to develop > Rebol API for DyBASE.
that's very, very cool!
> I read Rebol manual but some questions are still not clear for me. > Can some Rebol guru suggest me the best way of dynamic instantiation > of object (so that structure of the object is not known at compile > time)?
fortunately that's rather easy. b: copy [] append b to-set-word "foo" append b "bar" obj: make object! b probe obj make object! [ foo: "bar" ]
> For example I have block containing field names and values: > ["x" 1 "y" 2 "z" 3] > I want to construct object with these fields, so that result will be > the same as after creating object using "make": > obj: make object! [x: 1 y: 2 z: 3]
you'll probably prefer to construct objects like shown above, but ... prepare: func [ x ] [ r: make type? x length? x foreach [ k v ] x [ repend r [ to-set-word k v ] ] r ] make object! prepare ["x" 1 "y" 2 "z" 3] best regards, -- chris

 [3/5] from: knizhnik:garret:ru at: 6-Dec-2003 19:06


Hello Christian, Thank you very much! "to-set-word" - is what I have missed. And "prepare" function is exactly what I need. Saturday, December 6, 2003, 6:37:09 PM, you wrote:
>> I am developer of object oriented database for dynamic languages >> (www.garret.ru/~knizhnik/dybase.html) >> Currently it supports PHP, Python and Ruby. Now I am going to develop >> Rebol API for DyBASE.
CL> that's very, very cool!
>> I read Rebol manual but some questions are still not clear for me. >> Can some Rebol guru suggest me the best way of dynamic instantiation >> of object (so that structure of the object is not known at compile >> time)?
CL> fortunately that's rather easy. CL> b: copy [] CL> append b to-set-word "foo" CL> append b "bar" CL> obj: make object! b CL> probe obj CL> make object! [ CL> foo: "bar" CL> ]
>> For example I have block containing field names and values: >> ["x" 1 "y" 2 "z" 3] >> I want to construct object with these fields, so that result will be >> the same as after creating object using "make": >> obj: make object! [x: 1 y: 2 z: 3]
CL> you'll probably prefer to construct objects like shown above, but ... CL> prepare: func [ x ] [ CL> r: make type? x length? x CL> foreach [ k v ] x [ CL> repend r [ to-set-word k v ] CL> ] CL> r CL> ] CL> make object! prepare ["x" 1 "y" 2 "z" 3] CL> best regards, CL> -- chris -- Best regards, Konstantin mailto:[knizhnik--garret--ru]

 [4/5] from: greggirwin:mindspring at: 6-Dec-2003 9:25


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. That's great! I think someone mentioned DyBase here not too long ago. Christian already answered your question, but please don't hesitate to ask more questions here. I think a lot of us would be glad to help, and there are some real gurus here so, if it can be done, someone here will know how to do it. You may even get a volunteer or two to help you! --Gregg

 [5/5] from: doug:vos:eds at: 9-Dec-2003 8:45


Konstantin - have you tried this?
>> obj: make object! [x: 1 y: 2 z: 3] >> x: mold obj
== { make object! [ x: 1 y: 2 z: 3 ]}
>> obj: do x >> probe obj
make object! [ x: 1 y: 2 z: 3 ]
>>
And other ways of examining objects:
>> first obj
== [self x y z]
>> third obj
== [x: 1 y: 2 z: 3]