Hi, Elan. You wrote:

Hi Ladislav,

I like what you did here. What it does not do, is prevent code duplication.
-----
It really does, see later...
-----
I copied the stuff as you wrote it into the REBOL console and added one
more, important expression after creating the object 'b:
>> b: make a [num: num + 1]

This additional expression was probe b

>> probe b

make object! [
    num: 2
    messages:
    make object! [
        get-num: func [
    sent...
    obj [object!]
    param
][obj/num
]
]
]


Lo and behold, b contains the message object you assigned to a. What have
we gained?

----------------------
We have gained a lot. CF:

>no-copying: same? get in a 'message get in b 'message
==true
>no-copying: same? get in a/message 'get-num get in b/message 'get-num
==true
--------------------


The point of my example was to demonstrate that we could prevent some of
the code from 'a from getting duplicated in 'b by using use contexts. Your
example is very elegant, but fails to solve the problem.

-------
Again, it does 8^)

Ladislav
-------

Elan

At 12:19 PM 12/1/99 +0100, you wrote:
>An example code concerning inheritance of object messages:
>
>Rebol[
>    Purpose: "Demonstrate non-copied object messages."
>    ]
>
>;Define the object without messages
>a: make object! [
>    num: 1
>    ;Other non-message attributes here...
>    messages: none
>    ]
>
>;Now define the messages, common for all descendants.
>;These are created only once
>;and aren't copied as long as
>;you don't change anything for a descendant...
>a/messages: make object! [
>    ;An example message
>    get-num: func [
>        ;every message must have access to object to which it has been
>sent...
>        obj [object!]
>        ;the room for message parameters...
>        param
>        ] [
>        ;This is the body of the message
>        obj/num
>        ]
>    ;Other messages here...
>    ]
>
>;Function to send messages, shouldn't be changed
>sm: func [obj [object!]  'message [word!] param [block!]] [
>    do in obj/messages message obj param
>    ]
>
>;Now you can use the code like this:
>>> sm a get-num []
>== 1
>>> b: make a [num: num + 1]
>>> sm b get-num []
>== 2
>
>
>- Ladislav
>
>
>


Reply via email to