[REBOL] Re: Creation of object with unknown structure
From: chris:langreiter at: 6-Dec-2003 16:37
> I am developer of object oriented database for dynamic languages
> 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
fortunately that's rather easy.
b: copy 
append b to-set-word "foo"
append b "bar"
obj: make object! b
make object! [
> 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 ]
make object! prepare ["x" 1 "y" 2 "z" 3]