Re: QUIT and ABORT

Liste des GroupesRevenir à cl forth 
Sujet : Re: QUIT and ABORT
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forth
Date : 18. May 2025, 09:16:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <100c51f$sfr3$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Mozilla Thunderbird
On 2025-05-18 06:58, dxf wrote:
On 18/05/2025 8:20 am, Ruvim wrote:
On 2025-05-17 17:28, dxf wrote:
On 17/05/2025 9:30 pm, Ruvim wrote:
On 2025-05-17 06:56, dxf wrote:
On 16/05/2025 9:12 pm, Ruvim wrote:
...
What solution do you mean?
>
Default behaviour of QUIT is Core QUIT.  THROW handles -56 by jumping to
Core QUIT.
>
If you make `throw` do this regardless of whether a user's exception frame exists in the exception stack, you make the `-56` error code uncatchable. So, the following test case will fail:
>
     t{  [: -56 throw ;] catch -> -56 }t
>
And what is the benefit?
>
Why should it fail?
>
You wrote: "THROW handles -56 by jumping to Core QUIT". Then the test should fail. But as you now show, you only meant the case where there is no user exception frame in the exception stack.
>
>
>
     [: -56 throw ;] catch  ok  -56 <
>
     [: -1 throw ;] catch  ok  -1 <
>
Okay, these cases are compliant.
>
>
>
     1 2 3 -56 throw
       ok  1 2 3 <
>
     1 2 3 -1 throw
       ok
>
This special handling of `-56` is inconsistent, not justified by practice, and complicates implementations.
>
>
Well, at least you don't object to the arguments about inconsistency and impracticality.
 I saw the pejoratives and was waiting for the arguments.
Hope, I have given enough arguments now (see also below).
Re practice — the burden of proof (providing examples) lies with the one who asserts that it is useful in practice.

Neither special nor complicated:
>
    -1  of s0 @ sp! fs0 @ fsp ! (core-quit) then
>
    -56 of (core-quit) then
>
Why do you empty stacks especially for `-1`?  Don't you do the same for `-2`, `-3`, `-4`, etc?
 The above was for explanatory purposes.  The actual code is here:
 https://pastebin.com/FAmufbki
An excerpt:
: error ( n -- )  \ part of THROW
   -1 of (abort) then
   -2 of boot cell+ @ 0= if .error then
      space errmsg 2@ type (abort) then
   -56 of 1 ?return then
   ."  THROW #" @base decimal swap . !base (abort) ;
: THROW ( n -- )
   ?dup if catcher @ ?dup 0= if error then rp!
   r> catcher ! 2r> fsp ! swap >r sp! drop r>  then ;
: CATCH ( xt -- n | 0 )
   sp@ fsp @ 2>r catcher @ >r rp@ catcher !
   execute 0 r> catcher ! 2r> 2drop ;
End of excerpt.
Note that in `error` you don't transfer control to `(abort)` only in the case of `-56`. The other differences are only related to the different error messages and can be factored out. For example, an equivalent definition:
   : error ( S: n\0 -- never )
     dup print-error
     -56 = if 1 ?return ( S: never ) then
     (abort)  ( S: never )
   ;
Another question is how are `evaluate` and `included` implemented?
I assume they use `catch`. Then your Forth system probably shows the following behavior in its terminal:
   999 -56 throw
      ok  999 <
   s" 999 -56 throw" evaluate
      ok
Of course, the first case shows a non-standard behavior. But moreover, the second case means that your catchable `quit` will not keep the data stack when it is called from `evaluate` or `included` (or `load`).
And what is the use of this?
When you call `quit` you probably want to eventually have on the stack all the passed values regardless how deep in program your call it, and how many exceptions frame are in the exception stack.

 
In many systems, the actions specified for `throw` when there is no user exception frame are implemented in `quit`:
>
   : translate-input ( any -- any )
     begin refill while interpret ?ok repeat
   ;
   : quit ( i*x -- never )   \ point (1)
     rdepth rndrop \ empty the return stack and exception stack
     0 set-source-id
     begin
       0 state ! \ enter interpretation state
       ['] translate-input catch dup
     while ( i*x n\0 )   \ point (2)
       ['] print-error catch if 6 bye-status then
       depth ndrop \ empty the data stack (and control-flow stack)
       fdepth fndrop \ empty the floating-point stack
     repeat bye \ end of stdin
   ;
>
(this is allowed as the programs are not affected)
>
And the system enters `quit` right after startup. So `throw` does not call `(core-quit)`, but non-locally *returns* to `(core-quit)` according to the system's exception frame.
>
This approach avoids the need to determine in `throw` whether a user exception frame exists, and allows to use `catch` in the words like `evaluate` and `included` to restore the input source. See an example implementation for `throw` in E.9.6.1.2275
<https://forth-standard.org/standard/implement#imp:exception:THROW>
>
>
The caveat/nuance is that the special handling of `-56` as in your example is not compatible with this approach at all.
>
This handling cannot be implemented in `throw`, since some exception frame always exists when `throw` is executed. And this handling cannot be implemented in `quit` because in the point (2) the data stack depth is already restored and is the same as in the point (1) plus one.
>
That's why I said this special handling of `-56` complicates implementations.
 That's hardly my problem or ANS'.
ANS made provision for a catchable QUIT.
Only reserving a throw code does not provide this provision.

It happens I could easily add it.  Those that want it will find a way.
 
--
Ruvim

Date Sujet#  Auteur
27 Mar 25 * "The Best Programming Language for the End of the World"198Alexis
27 Mar 25 +* Re: "The Best Programming Language for the End of the World"5Martin Nicholas
28 Mar 25 i`* Re: "The Best Programming Language for the End of the World"4Alexis
28 Mar 25 i `* Re: "The Best Programming Language for the End of the World"3Martin Nicholas
30 Mar 25 i  +- Re: "The Best Programming Language for the End of the World"1Alexis
30 Mar 25 i  `- Re: "The Best Programming Language for the End of the World"1Bernd Linsel
28 Mar 25 +* Re: "The Best Programming Language for the End of the World"7anthk
29 Mar 25 i`* Re: "The Best Programming Language for the End of the World"6mhx
29 Mar 25 i +- Re: "The Best Programming Language for the End of the World"1dxf
30 Mar 25 i +* Re: "The Best Programming Language for the End of the World"3anthk
5 Apr 25 i i+- Re: "The Best Programming Language for the End of the World"1anthk
6 Apr 25 i i`- Re: "The Best Programming Language for the End of the World"1sjack
31 Mar 25 i `- Re: "The Best Programming Language for the End of the World"1John Ames
30 Mar 25 +* Re: "The Best Programming Language for the End of the World"86sjack
1 Apr 25 i`* Re: "The Best Programming Language for the End of the World"85dxf
29 Apr 25 i `* Re: Why dial-a-standard is not a thing in Forth84Hans Bezemer
30 Apr 25 i  +* Re: Why dial-a-standard is not a thing in Forth80dxf
30 Apr 25 i  i+* Re: Why dial-a-standard is not a thing in Forth77Hans Bezemer
1 May 25 i  ii`* Re: Why dial-a-standard is not a thing in Forth76dxf
1 May 25 i  ii +* Re: Why dial-a-standard is not a thing in Forth3John Doe
1 May 25 i  ii i+- Re: Why dial-a-standard is not a thing in Forth1Stephen Pelc
1 May 25 i  ii i`- Re: Why dial-a-standard is not a thing in Forth1Anton Ertl
1 May 25 i  ii `* Re: Why dial-a-standard is not a thing in Forth72Hans Bezemer
2 May 25 i  ii  +- Re: Why dial-a-standard is not a thing in Forth1dxf
3 May 25 i  ii  `* Re: Why dial-a-standard is not a thing in Forth70dxf
3 May 25 i  ii   +* QUIT and ABORT (was: Why dial-a-standard is not a thing in Forth)68Anton Ertl
3 May 25 i  ii   i+- Re: QUIT and ABORT1dxf
3 May 25 i  ii   i+* Re: QUIT and ABORT65dxf
3 May 25 i  ii   ii`* Re: QUIT and ABORT64Anton Ertl
4 May 25 i  ii   ii +* Re: QUIT and ABORT62dxf
4 May 25 i  ii   ii i`* Re: QUIT and ABORT61Anton Ertl
5 May 25 i  ii   ii i +- Re: QUIT and ABORT1dxf
5 May 25 i  ii   ii i +* Re: QUIT and ABORT54dxf
5 May 25 i  ii   ii i i`* Re: QUIT and ABORT53Ruvim
5 May 25 i  ii   ii i i +- Re: QUIT and ABORT1Ruvim
6 May 25 i  ii   ii i i +* Re: QUIT and ABORT3dxf
6 May 25 i  ii   ii i i i+- Re: QUIT and ABORT1Anton Ertl
6 May 25 i  ii   ii i i i`- Re: QUIT and ABORT1Ruvim
6 May 25 i  ii   ii i i `* Re: QUIT and ABORT48dxf
6 May 25 i  ii   ii i i  +* Re: QUIT and ABORT3Ruvim
6 May 25 i  ii   ii i i  i+- Re: QUIT and ABORT1Anton Ertl
6 May 25 i  ii   ii i i  i`- Re: QUIT and ABORT1dxf
6 May 25 i  ii   ii i i  `* Re: QUIT and ABORT44Anton Ertl
6 May 25 i  ii   ii i i   `* Re: QUIT and ABORT43dxf
7 May 25 i  ii   ii i i    `* Re: QUIT and ABORT42Ruvim
8 May 25 i  ii   ii i i     +* Re: QUIT and ABORT40dxf
8 May 25 i  ii   ii i i     i`* Re: QUIT and ABORT39Ruvim
9 May 25 i  ii   ii i i     i `* Re: QUIT and ABORT38dxf
9 May 25 i  ii   ii i i     i  `* Re: QUIT and ABORT37Ruvim
9 May 25 i  ii   ii i i     i   `* Re: QUIT and ABORT36dxf
9 May 25 i  ii   ii i i     i    +* Re: QUIT and ABORT2albert
10 May 25 i  ii   ii i i     i    i`- Re: QUIT and ABORT1dxf
9 May 25 i  ii   ii i i     i    `* Re: QUIT and ABORT33Ruvim
10 May 25 i  ii   ii i i     i     +- Re: QUIT and ABORT1dxf
13 May 25 i  ii   ii i i     i     `* Re: QUIT and ABORT31Ruvim
14 May 25 i  ii   ii i i     i      `* Re: QUIT and ABORT30dxf
14 May 25 i  ii   ii i i     i       `* Re: QUIT and ABORT29Ruvim
15 May 25 i  ii   ii i i     i        `* Re: QUIT and ABORT28dxf
16 May 25 i  ii   ii i i     i         `* Re: QUIT and ABORT27Ruvim
16 May 25 i  ii   ii i i     i          `* Re: QUIT and ABORT26dxf
16 May 25 i  ii   ii i i     i           `* Re: QUIT and ABORT25Ruvim
17 May 25 i  ii   ii i i     i            `* Re: QUIT and ABORT24dxf
17 May 25 i  ii   ii i i     i             `* Re: QUIT and ABORT23Ruvim
17 May 25 i  ii   ii i i     i              `* Re: QUIT and ABORT22dxf
17 May 25 i  ii   ii i i     i               `* Re: QUIT and ABORT21Ruvim
18 May 25 i  ii   ii i i     i                `* Re: QUIT and ABORT20dxf
18 May 25 i  ii   ii i i     i                 +* Re: QUIT and ABORT2Anton Ertl
18 May 25 i  ii   ii i i     i                 i`- Re: QUIT and ABORT1dxf
18 May 25 i  ii   ii i i     i                 `* Re: QUIT and ABORT17Ruvim
18 May 25 i  ii   ii i i     i                  `* Re: QUIT and ABORT16dxf
19 May 25 i  ii   ii i i     i                   `* Re: QUIT and ABORT15Ruvim
20 May 25 i  ii   ii i i     i                    `* Re: QUIT and ABORT14dxf
24 May 25 i  ii   ii i i     i                     `* Re: QUIT and ABORT13Ruvim
24 May 25 i  ii   ii i i     i                      +* Re: QUIT and ABORT7mhx
24 May 25 i  ii   ii i i     i                      i+* Re: QUIT and ABORT5Ruvim
24 May 25 i  ii   ii i i     i                      ii`* Re: QUIT and ABORT4mhx
24 May 25 i  ii   ii i i     i                      ii +- Re: QUIT and ABORT1Ruvim
24 May 25 i  ii   ii i i     i                      ii +- Re: QUIT and ABORT1Anton Ertl
24 May 25 i  ii   ii i i     i                      ii `- Re: QUIT and ABORT1albert
24 May 25 i  ii   ii i i     i                      i`- Re: QUIT and ABORT1Anton Ertl
24 May 25 i  ii   ii i i     i                      +- Re: QUIT and ABORT1albert
24 May 25 i  ii   ii i i     i                      `* Re: QUIT and ABORT4dxf
24 May 25 i  ii   ii i i     i                       `* Re: QUIT and ABORT3Ruvim
25 May 25 i  ii   ii i i     i                        `* Re: QUIT and ABORT2dxf
26 May 25 i  ii   ii i i     i                         `- Re: QUIT and ABORT1dxf
8 May 25 i  ii   ii i i     `- Re: QUIT and ABORT1Ruvim
5 May 25 i  ii   ii i `* Re: QUIT and ABORT5mhx
6 May 25 i  ii   ii i  +- Re: QUIT and ABORT1dxf
7 May 25 i  ii   ii i  `* Re: QUIT and ABORT3albert
7 May 25 i  ii   ii i   `* Re: QUIT and ABORT2minforth
7 May 25 i  ii   ii i    `- Re: QUIT and ABORT1dxf
4 May 25 i  ii   ii `- Re: QUIT and ABORT1dxf
4 May 25 i  ii   i`- Re: QUIT and ABORT (was: Why dial-a-standard is not a thing in Forth)1albert
5 May 25 i  ii   `- Re: Why dial-a-standard is not a thing in Forth1dxf
30 Apr 25 i  i`* Re: Why dial-a-standard is not a thing in Forth2sjack
1 May 25 i  i `- Re: Why dial-a-standard is not a thing in Forth1dxf
30 Apr 25 i  `* Re: Why dial-a-standard is not a thing in Forth3albert
30 Apr 25 i   `* Re: Why dial-a-standard is not a thing in Forth2Hans Bezemer
30 Apr 25 i    `- Re: Why dial-a-standard is not a thing in Forth1mhx
4 Apr 25 +- Re: "The Best Programming Language for the End of the World"1dxf
5 Apr 25 `* Re: "The Best Programming Language for the End of the World"98dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal