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 <[EMAIL PROTECTED]>  --  REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

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

Reply via email to