Hi Gabriele,
you wrote:
>Hello [EMAIL PROTECTED]!
>To create simpler methods, why not binding them to the right
>object at the right time?
>
>Something like:
>
>!: func [
> object [object!]
> 'method [word!]
> /local mth
>] [
> ; let's skip error checking for clarity
> mth: get in object/methods method
> bind second :mth in object 'self
> return :mth
>]
>
A work of beauty. Simple and effective. Of the different approaches in this
thread (including mine, which your function comments on) this is definitely
my favorite. Your approach also simplifies the embedded method object to:
root: make object! [
var: none
methods: make object! [
get-var: func [] [ var ]
sumnum: func [other [object!] [ (do ! other get-var) + (self get-var) ]
]
]
No need for the member I called object. En passant, Gabriele, I am
surprised that 'bind actually does its job in this example. I have had
problems using bind sensibly. Somehow, I always manage to get bind to
complain that it cannot resolve one or the other thing.
Ladislav, I withdraw my proposed ! for Gabriele's. It avoids having to keep
in mind which object the word 'object will be bound to, which can become a
problem, if you use it thoughtlessly, as you documented. I think we should
agree on Gabriele's function and add a little error handling.
Do you see any problems with it?
Elan