On 05-Apr-02, Robert M. Muench wrote:

> Hi, my current applications uses object! to define a set of business
> objects the application than manipulates. While further developing
> the application the definition of those objects might change. New
> releases need to update the older business objects on-the-fly to
> keep it as simple as possible for the user. To be able to do this I
> have a migration function that transforms an old object step by step
> to the newest version. The pattern is like this:

> migrate: func [...] [
>     if old_object/business_object_version = 1.0.0 [
>         ; update to 1.1.0
>     ]

>     if old_object/business_object_version = 1.1.0 [
>         ; update to 1.2.3
>     ]
>     ...
> ]

> What needs to be done to update an object? Well, there are only four
> things:

> 1. Add a new variable and value to an object
> 2. Rename a variable in an object
> 3. Delete a variable from an object
> 4. Set a different value for an existing variable in an object

> I really would like to have object manipulation functions for 1, 2
> and 3. Where 1 can be solved by short function;-).

> Does anybody has a good idea how to do 2. and 3.? Robert

Others will know if you can do it directly, but you can access an
object's block by looking at its third value.  ie...

>> obj: make object! [a: 10 b: 20]
>> third obj
== [a: 10 b: 20]

You could use that to get the object's block, alter it, and then make
the object again...

>> obj-blk: copy third obj
== [a: 10 b: 20]
>> remove obj-blk
== [10 b: 20]
>> insert obj-blk [aa:]
== [10 b: 20]
>> obj: make object! obj-blk
>> ? obj
OBJ is an object of value: 
make object! [
    aa: 10
    b: 20
]

There's probably a better way though...

Oh, and your problem 1 is already catered for with 'make...

>> obj: make obj [c: 30]
>> ? obj
OBJ is an object of value: 
make object! [
    aa: 10
    b: 20
    c: 30
]


-- 
Carl Read

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to