![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Thanks for the replies Elizabeth and Rick. After some further study, I
believe this is sinking in.
However, in Rick's example I think there is an extra DROP. If CATCH
returns non-zero, the stack depth would equal the stack depth before the
CATCH plus one for the return code. In other words, the stack depth
will be restored but the stack *content* is indeterminate.
The three items dropped if catch returns true are not predictable.
Thanks,
Mike
----------------------------------------------------
VARIABLE POO
: TEST ( a b -- )
+ POO ! POO @ 100 > THROW ;
: TRY ( a b -- )
['] TEST CATCH IF
( We now cleanup stack - depth is known, contents is NOT )
DROP DROP ( DROP ) \ <<< One too Many???
." Poo is greater than 100"
THEN ;
-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com]On Behalf
Of Rick VanNorman
Sent: Wednesday, April 04, 2001 10:56 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: CATCH
For instance,
VARIABLE POO
: TEST ( a b -- )
+ POO ! POO @ 100 > THROW ;
: TRY ( a b -- )
['] TEST CATCH IF DROP DROP DROP
." Poo is greater than 100"
THEN ;
The three items dropped if catch returns true are not predictable.
If catch returns zero, the stack effect is exactly what the word
caught would be.
Hope this helps.
Rick
*********** REPLY SEPARATOR ***********
On 4/4/2001 at 10:35 AM Mike Ghan wrote:
>Hello all, does each CATCH require a matching THROW or is it possible
>to use CATCH alone and simply drop it's result. For example:
>
>['] FOO CATCH ( throw_code ) \ FOO creates structures
> \ which must be destroyed.
>['] CLEANUP CATCH DROP \ Need to return here
> \ regardless of error.
>DESTROY-FOO \ Destroy FOO's structures.
>( throw-code ) THROW \ Act on first CATCH
> \ throw code.
>
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Received on Wed Apr 04 2001 - 12:49:46 PDT
This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 03:04:18 PST