Someone said you can have (implementation inheritance) with Rebol using get. So I tried:
shape: context [
x: 0
y: 0
draw: func['object][
probe get object
]
]
circle: make shape [
radius: 10
draw: get in shape 'draw
]
rectangle: make shape [
draw: get in shape 'draw
]
I want to pass the object by reference not by value so I pass only the name using ‘Object. But then I have to call it like this
circle/draw 'circle
which is rather lame as I need to repeat the name circle twice while in usual inheritance there is the this keyword which avoid this kind of unatural syntax. Is there a more elegant way ?
Thanks.
There is a
selfword. At the risk of creating a false sense of certainty about that, I’ll give you an example that presumably does what you want:Here we’ve made functions that take zero arguments by calling the base class function with the appropriate “self”
Beware: like other words, it gets bound…and the binding sticks. This can get tricky once you start working with abstractions…
Calling
triangle/drawwill probably surprise you. You’re in the object method and selfWordAlias returns the word “self”. But the notion of self was captured and bound at the time the selfWordAlias was defined, which was in the global system context. So that’s what you get back.There are tools for dealing with this, but make sure you’ve got a firm grip on Scoping in Rebol !