Sujet : Re: Back & Forth - Co-routines
De : albert (at) *nospam* spenarnc.xs4all.nl
Groupes : comp.lang.forthDate : 04. Feb 2025, 13:26:26
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$68d49e22$0e1b270a@ce4705a037955a82>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
874j1aycdt.fsf@nightsong.com>,
Paul Rubin <
no.email@nospam.invalid> wrote:
albert@spenarnc.xs4all.nl writes:
I maintain that if you are not in a recursive call for
a function with locals, and you try to catch the same function
call, everything is fine.
>
The thing about exceptions is that they occur unexpectedly.
Yeah right.
Think about it precisely.
You are in fun , recursively called from fun. A throw occurs in
this invocation but not from the external invocation.
You did not catch it in the external fun (otherwise all would be under
control). Can that cause problems by no restoring the variable?
your recursive function prints something, and that works the first few
times, but then the printer runs out of paper and there is an i/o
exception. It's not the recursive function's job to handle this. The
exception throws to some outer level handler that asks the user to fix
the problem.
The printer runs out of paper during a recursive fibonacci call where you
print physically all the iteration stuff on a separate page.
You add new paper to the printer and you want to continue.
That is not a good example.
You call 100 'fib catch (don't mind the paper spill, but yes
the printer is guaranteed to run out of paper).
The problem is that you cannot recover! The catch makes no sense,
because the throw is made from in inner fib call.
Or do you can propose to adorn all recursive calls
: fib ...
'fib catch ( enormous recovery for all cases including printer errors )
...
'fib catch ( enormous recovery for all cases including printer errors )
..
;
>
Adding (LOCAL) to a Forth interpreter should normally not be too
difficulot, if you control the interpreter implementation. It's the
right way to do stuff like this. Why mess around with all that awful
stack juggling for a half-working and woefully slow solution?
That is not the point. We are discussing whether or not the
present solution is possible.
It is an academic discussion, because I don't use locals at all,
if they are absolutely necessary I use my enhanced `[ instead
of any style of locals
: root [ variable a variable b variable c ]
c ! b ! a !
\ now insert the famous quadratic root formula
[ hide a hide b hide c ] \ Prevent "not unique messages"
;
Remark that is doesn't introduce any unfamiliar syntax,
only does away with "Forth shall not nested definitions"
(Says who?)
It is perfectly clear that this doesn't work where root
call itself recursively. But it doesn't call itself, so fine.
Groetjes Albert
-- Temu exploits Christians: (Disclaimer, only 10 apostles)Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style WallArt For Home, Office And Garden Decor - Perfect For Windows, Bars,And Gifts For Friends Family And Colleagues.