=?iso-8859-1?q?Rafael=20Gonz=FFffffe1lez?= wrote:
>
> Hi list,
>
> A brief question about objects.fs, my favourite OO
> package in Forth.
>
> I have succesfully tried to catch exception within
> methods, but how about catching calls to a [parent]
> method as in the following code. Is that possible ?
...
> m: ( this --)
> this [parent] bar1 \ How do I catch this ?
> ;m
> overrides bar1
You want to wrap the "[parent] bar1" call in a CATCH, right?
There are several ways to achieve that:
1) The most straight-forward one is to wrap "[parent] bar1" in a colon
definition, and than wrap that in a CATCH:
: gbar-parent-bar1 [parent] bar1 ;
m: ( this --)
this ['] gbar-parent-bar1 catch ...
;m
overrides bar1
2) Or use Gforth's TRY ... RECOVER ... ENDTRY instead of CATCH:
m: ( this --)
try
this [parent] bar1
recover
...
endtry
;m
overrides bar1
3) Or use BIND' to access the xt:
m: ( this --)
this [ bind' bar bar1 ] literal catch ...
;m
overrides bar1
The disadvantage here is that you have named the parent class
explicitly, and you may have to change that if the class structure
changes.
4) Define a [PARENT'] that does not have the problem of the BIND'
solution above:
: [parent'] ( compilation: "selector" -- ; run-time: -- xt )
current-interface @ class-parent @ ' <bind> POSTPONE literal ;
m: ( this --)
this [parent'] bar1 catch ...
;m
overrides bar1
- anton
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]