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

Business Object Versioning

 [1/12] from: robert:muench:robertmuench at: 5-Apr-2002 10:42


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

 [2/12] from: anton:lexicon at: 5-Apr-2002 20:58


Yes, I and others miss these functions too. Especially 1.
> 1. Add a new variable and value to an object > 2. Rename a variable in an object
<<quoted lines omitted: 4>>
> 1 can be solved by short function;-). > Does anybody has a good idea how to do 2. and 3.? Robert
I don't think it's possible. From memory Holger said it's not possible to add words to an existing object. Anton.

 [3/12] from: carl:cybercraft at: 6-Apr-2002 0:15


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
<<quoted lines omitted: 21>>
> 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

 [4/12] from: rotenca:telvia:it at: 5-Apr-2002 14:16


Hi Robert
> 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.?
A rename func: rename-ob: func [o name1 name2][context head change find third o to-set-word name1 to-set-word name2]
>> o: context [a: 1 b: 2] >> probe rename-ob o 'a 'c
make object! [ c: 1 b: 2 ] but there are many many situations in which it fails: o: context [a: 1 b: [a: 3]] o: context [a: 1 b: func [] [a: 3]] rename-ob o 'a 'c change the first a: but not the second one. The same for delete: delete-ob: func [o name][context head remove/part find third o to-set-word name 2] --- Ciao Romano

 [5/12] from: sunandadh:aol at: 5-Apr-2002 6:34


Robert:
> I really would like to have object manipulation functions for 1, 2 and 3. > Where > 1 can be solved by short function;-)
I don't know any easy way. I had to do something similar when I wanted an object that was made up of the differences between two other objects. aa: make object! [a: 1 b: 2 c: 3] bb: make object! [b: 2 a: 99 d: 4] print mold ob-diff aa bb make object! [a: 99 c: 3 d: 4] I won't shame myself by published the highly hacked code -- which only works for simple variables anyway -- but basically, I compare the two objects, compose a block of differences, and then Do that block: do [make object! [a: 2 c: 3 d: 4]] You might try a similar technique to build a new object to replace your original one, Sunanda.

 [6/12] from: anton:lexicon at: 6-Apr-2002 1:14


> > 1. Add a new variable and value to an object > Oh, and your problem 1 is already catered for with 'make... > > >> obj: make obj [c: 30] > Carl Read
No, it creates a new object. Now we have two objects. The value of 'obj has shifted from the old object to the new one. Anything that was referring to the old object will not be able to see the "changes". Of course, the above approach is useful, but to modify an object in place cannot be done right now. Anton.

 [7/12] from: g:santilli:tiscalinet:it at: 5-Apr-2002 21:18


Hi Robert, On Friday, April 05, 2002, 10:42:53 AM, you wrote: RMM> I really would like to have object manipulation functions for 1, 2 and 3. Where RMM> 1 can be solved by short function;-). Well, I think you already know we can only workaround currently. :-) I see Romano has provided some, but they're using THIRD which has big problems:
>> obj: context [a: 'word b: func [x] [print x]] >> obj2: context third obj
** Script Error: word has no value ** Where: context ** Near: a: word b: func [x][print x]
>> obj/a: 1
== 1
>> obj2: context third obj
** Script Error: none is missing its x argument ** Where: context ** Near: b: func [x][print x] etc. so I'll try with a different approach. :) add-word: func [ "Create a new object like the old one but with a word added" object [object!] word [word!] ] [ make object reduce [to-set-word word none] ] rename-word: func [ "Create a new object like the old one but with a word renamed" object [object!] old-word [word!] new-word [word!] /local template ] [ template: clear [] ; not recursive, use copy if you need it to recurse ; I cannot think of a simpler way, anyone? ; (if you don't mind creating two objs you could remove then add...) foreach word next first object [ insert tail template to-set-word either word = old-word [new-word] [word] ] insert tail template none template: context template foreach word next first template [ set/any in template word get/any in object either word = new-word [old-word] [word] ] template ] remove-word: func [ "Create a new object like the old one but with a word removed" object [object!] word [word!] /local template ] [ template: clear [] ; see above foreach old-word next first object [ if old-word <> word [insert tail template to-set-word old-word] ] insert tail template none template: context template foreach word next first template [ set/any in template word get/any in object word ] template ] They work as follows:
>> obj: context [a: 1 b: 2 c: 'word d: func [x] [print x]] >> probe add-word obj 'e
make object! [ a: 1 b: 2 c: 'word d: func [x][print x] e: none ]
>> probe rename-word obj 'd 'e
make object! [ a: 1 b: 2 c: 'word e: func [x][print x] ]
>> probe remove-word obj 'c
make object! [ a: 1 b: 2 d: func [x][print x] ] HTH, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [8/12] from: carl:cybercraft at: 6-Apr-2002 9:41


On 06-Apr-02, Anton wrote:
>>> 1. Add a new variable and value to an object >> Oh, and your problem 1 is already catered for with 'make...
<<quoted lines omitted: 6>>
> Anything that was referring to the old object will not > be able to see the "changes".
You're right of course Anton. A bit of a lazy post on my behalf.
> Of course, the above approach is useful, > but to modify an object in place cannot be done right now. > Anton.
-- Carl Read

 [9/12] from: robert:muench:robertmuench at: 6-Apr-2002 15:22


Hi, concerning all this object versioning stuff. I thought about using a pattern like Carl did for contacts. There he uses a block of name value pairs. Blocks can be altered quite easy. Might be a better approach. Than we only need a set of functions to search only for some name/value pairs etc. Simple "block-object-oriented" database... Robert

 [10/12] from: robert:muench:robertmuench at: 6-Apr-2002 15:22


> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]On Behalf Of
<<quoted lines omitted: 4>>
> Others will know if you can do it directly, but you can access an > object's block by looking at its third value. ie...
Hi, yes I tried this too but I missed the step to create a new object than ;-). I thought I can dynamically alter the third block. But this doesn't work. IMO this would be a very elegant functionality.
> You could use that to get the object's block, alter it, and then make > the object again...
Sounds like an object-altering dialect is needed ;-).
> Oh, and your problem 1 is already catered for with 'make...
But only if the origianl object-layout is available. But that's not the case, within my application I only have the latest version encoded. So I need to alter the old objects step-by-step to the new ones. And I try to make it in-place without copying around to much. Robert

 [11/12] from: robert:muench:robertmuench at: 6-Apr-2002 15:22


> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]On Behalf Of
<<quoted lines omitted: 3>>
> Subject: [REBOL] Re: Business Object Versioning > Well, I think you already know we can only workaround currently.
;-) Yep...
> etc. so I'll try with a different approach. :) > add-word: func [
<<quoted lines omitted: 4>>
> make object reduce [to-set-word word none] > ]
Here is my solution: extend-object: func ['obj-word [word!] 'word [word!] value [any-type!] /local the-obj][ all [not object? the-obj: get obj-word make error! "No object provided."] if in the-obj word [ set in the-obj word value return the-obj ] set obj-word make the-obj reduce [to-set-word word value] ] Looks pretty the same :-))
> rename-word: func [ > ... > > remove-word: func [ > ...
Great stuff! Thanks a lot.
> template: clear [] ; not recursive, use copy if you need it to recurse
I didn't get it here. Can you explain it a bit more? Robert

 [12/12] from: g:santilli:tiscalinet:it at: 7-Apr-2002 11:56


Hi Robert, On Saturday, April 06, 2002, 3:22:22 PM, you wrote:
>> template: clear [] ; not recursive, use copy if you need it to recurse
RMM> I didn't get it here. Can you explain it a bit more? Robert I'm reusing the same block across function calls, to avoid useless memory allocations. This is fine if you are not calling the function recursively (which I don't think you'll be doing in your case, and my functions don't do anyway), since the block is not returned. I always put a warning when I use this technique, because it's easy to forget of it and then difficult to find the bugs. :) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted