[REBOL] How do I dynamically extend an object! instance Re:(4)
From: bobr:dprc at: 13-Sep-2000 12:16
At 07:48 AM 9/13/00 +0200, [lmecir--geocities--com] wrote:
>Hi bobr,
>
>what are the results of the code below and which version of Rebol you use?
>
>-Ladislav
we have a "production" version 2.1.2.3.1
in which this works (except for the error below).
[
a: make object! [
addr: "417 howser st"
name: "joyce haversham"
]
d: make object! [ user: a ]
; now modify in-place
wds: first a
vals: second a
append wds 'email
append vals "[joyce--someplace]"
print mold d ; works yay!
save %mytmp a ; works
probe a ; works
b: make a ; works and retains new fields (but these too are inaccessable
via b/email path method )
print a/email ; fails
]
that is, after the words are modified (append/remove)
all references to the object are also changed in place without creating
a new object. this works good for us.
however paths referring to the new words in the object dont work
unless the object is saved and reinstantiated (save/load)
or unless a new object is made which violates the in-place ideal.
so for now, if we want to create a new path/word
into an object and we must use the new paths right away then
we have to live with creating a new instance of the object.
to minimize the effect on running system maint
we try to add words to an object just after loading it
before anythisg else (another object) has had a chance
to attach to it.
[
fileloaded: %dbrecords/u0012
tmp: do load fileloaded ; load a single record
if anyfieldsmissing [
tmp: object-addword/initial tmp resave-as fileloaded
tmp: object-addword/initial tmp name "?name" ; should
already be present
tmp: object-addword/initial tmp addr "?street addr" ; should
already be present
tmp: object-addword/initial tmp phone "011 978 555 1212"
tmp: object-addword/initial tmp county "maui"
tmp: object-addword/initial tmp email "[*--*--*][.*]"
]
append in-memeory-records tmp ; attach to in-system lists
; from here on all sorts of things attach to this puppie
]
it will be a corporate decision wether we upgrade to a newer version
which does not support inplace mods to the fields (words) of a record.
depends on the return on investment for the re-engineering work.
>> At 09:09 PM 9/10/00 +0200, [lmecir--geocities--com] wrote:
>> >Hi bobr,
>> >> - can it be done without creating a new instance?
>> >
>> >No.
>>
>>
>> ok here is my latest method for extending an object in-situ.
>> the example hasnt been turned into a function
>> and I hope I am not violating any storage but here goes...
>> [
>>
>> a: make object! [
>> addr: "417 howser st"
>> name: "joyce haversham"
>> ]
>>
>> wds: first a
>> vals: second a
>>
>> append wds 'email
>> append vals "[joyce--someplace]"
>>
>> probe a
>>
>> ]
>>
>> now this -looks- fine,
>> you can save/probe/mold the object and read it back in
>> with no problems. best of all no new object
>> is instantiated so all references to a are updated as well.
>>
>> for some reason you cannot access the new items
>> by a path. as soon as you type a/email
>> there is an error.
>>
>>
>> remove seems to be just as simple but
>> I think I will stay away from it
>> till I know exactly is going on with a/email
>> and why the path doesnt work before I drop
>> something out of the middle.
>>
>>
>> ;# mailto: [bobr--dprc--net]
>>
>>
>
;# mailto: [bobr--dprc--net]