• Re: bye with exit status

    From albert@spenarnc.xs4all.nl@21:1/5 to ruvim.pinka@gmail.com on Wed Nov 6 14:58:15 2024
    In article <vgfmfe$22uop$1@dont-email.me>,
    Ruvim <ruvim.pinka@gmail.com> wrote:
    Many Forth systems running under an operating system provide
    system-specific capabilities to terminate with an exit status [1].
    Note that it is not Forth-system-specific but operating-system specific.
    Once you leave the Forth, the exit status is non-existent, as far
    as Forth is concerned.


    For example, the following code fragments have stack effect ( n -- ⊥ )
    and use n as the process exit status:

    SwiftForth "exitstatus ! bye"
    VfxForth "exitcode ! bye"
    Gforth "(bye)"
    ciforth "exit-code ! bye"
    mf3 "sysexit"
    Post4 "bye-code"
    SP-Forth "halt"

    Could you suggest some names for the word with this functionality so
    that one of them can be standardized?

    A turnkey process should not detect an error, or if it is, that
    error should be the users fault.
    In ciforth I immediately terminate a turnkey process in case of an error.
    (The user has an alternative: starting a Forth, then 'SOMETHING CATCH.
    He misses nothing.)
    The error number is the same as reported in the interpreter and is
    documented in the application, or the Forth itself.


    This word should not output any messages.
    Which word? Do you propose the functionality of Gforth's (bye)
    in the standard?



    There are at least three different notions of premature termination of
    code execution:
    — return from a Forth definition (to the caller)
    — terminate a thread/task
    — terminate the process
    And they should not be confused.

    IMO all error conditions should have a distinct error number.
    So a distinction between the conditions must be made in the
    documentation of this error number. No need to theorize about
    a common convention between the types of error.

    The second set me thinking. This means that EXIT-CODE should be
    a user variable. I follow Chuck Moore, I build that bridge if
    I must cross the Rubicon.

    [1] <https://en.wikipedia.org/wiki/Exit_status>
    --
    Ruvim

    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anthony Howe@21:1/5 to Ruvim on Wed Nov 6 11:51:16 2024
    On 2024-11-06 07:12, Ruvim wrote:
    For example, the following code fragments have stack effect ( n -- ⊥ )
    and use n as the process exit status:

      SwiftForth "exitstatus ! bye"
      VfxForth   "exitcode ! bye"

    Don't like this behaviour; it comes off like a side-effect.

      Gforth     "(bye)"

    I'd be content with `(bye)`.

      ciforth    "exit-code ! bye"
      mf3        "sysexit"
      Post4      "bye-code"

    Just because there was nothing in the standard and I was not aware of what others did. I had considered `OSEXIT` or `EXIT-TO-HOST`, but neither of these come off as related to `BYE` when you see the name.

    (bye)
    bye-code
    bye-status
    bye-exit
    bye-bye ( ok I'm getting silly; point is it should relate to BYE )

      SP-Forth   "halt"

    I do _not_ like this choice, because I associate "halt" with system halt, ie. `shutdown -h now` or `halt(1)`.

    And certainly not `hcf`.

    Could you suggest some names for the word with this functionality so that one of
    them can be standardized?

    This word should not output any messages.


    --
    Anthony C Howe
    achowe@snert.com BarricadeMX & Milters http://nanozen.snert.com/ http://software.snert.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@21:1/5 to All on Wed Nov 6 17:15:43 2024
    Over-standardisation is for control freaks.
    For example, in some systems a BYE can also
    trigger a series of shutdown sequences,
    not just a fallback to OS level.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to All on Wed Nov 6 18:27:26 2024
    iForth:

    T: BYE ( -- ) 0 TERMINATE T; ANS

    TERMINATE IFORTH
    ( n -- )
    Disconnect the server from the processor. Remove the server
    program on the host computer and let the server return the
    implementation defined error code n to the operating system.
    See also: BYE

    : TERMINATE
    ??CR [ =FILES ] [IF] FLUSH BLOCK-FID @ ?DUP
    IF CLOSE-FILE DROP 0 BLOCK-FID ! THEN
    [THEN]
    BYE! T; ( error-level -- )

    BYE! IFORTH
    ( -- )
    Send the 'disconnect server' command over the boot link to the
    server (if there is one). The server disconnects upon receiving
    this message and exits itself. All knowledge about open files
    is lost. If there is no server this command is the same as BYE .
    See also: BYE

    -marcel

    Same as remarked by minforth: there is a exit-handler chain in
    which the user can plug arbitrary routines.

    The chained handlers were very popular with Hanno Schwalm because
    he loved generating executables. I don't use them myself because
    iForth is the default shell for my main activities.

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anthony Howe@21:1/5 to Ruvim on Thu Nov 7 13:50:48 2024
    On 2024-11-07 06:56, Ruvim wrote:
    I would like to find a more appropriate name for this word than "bye-status".

    (bye) ( u -- )

    Seems apropos, short, to the point and indicative of an internal word. Default can be defined to return to the host OS with an exit status `u`, but maybe be replaced in (unhosted) environments to perform some sort of system reset, power cycle, or other implementation defined system reset.

    `terminate` is a good candidate, but it's unclear what it should terminate — a
    thread/task, or a process, or the own process, or the own thread.

    TERMINATE could have the same meaning as SIGTERM *:

    SIGTERM (Terminated)
    This signal is the default signal sent by kill(1) and represents a
    user or administrator request that a program shut down [normally].

    * Other signals result in abnormal termination.


    --
    Anthony C Howe
    achowe@snert.com BarricadeMX & Milters http://nanozen.snert.com/ http://software.snert.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ron AARON@21:1/5 to Anthony Howe on Fri Nov 8 09:08:29 2024
    8th uses the word "die", e.g. 1 die
    The word "bye" is 0 die.

    On 07/11/2024 20:50, Anthony Howe wrote:
    On 2024-11-07 06:56, Ruvim wrote:
    I would like to find a more appropriate name for this word than "bye-
    status".

    (bye) ( u -- )

    Seems apropos, short, to the point and indicative of an internal word. Default can be defined to return to the host OS with an exit status `u`,
    but maybe be replaced in (unhosted) environments to perform some sort of system reset, power cycle, or other implementation defined system reset.

    `terminate` is a good candidate, but it's unclear what it should
    terminate — a thread/task, or a process, or the own process, or the
    own thread.

    TERMINATE could have the same meaning as SIGTERM *:

     SIGTERM (Terminated)
              This signal is the default signal sent by kill(1) and represents a
              user or administrator request that a program shut down [normally].

    * Other signals result in abnormal termination.



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to All on Fri Nov 8 06:26:00 2024
    The word PROBLEM ( u -- ) might be more suitable?

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to mhx on Fri Nov 8 08:29:13 2024
    mhx@iae.nl (mhx) writes:
    Same as remarked by minforth: there is a exit-handler chain in
    which the user can plug arbitrary routines.

    In Gforth BYE is a deferred word, with the intention that it can be
    extended with cleanup actions.

    The disadvantage of this approach in connection with the non-0 exit is
    that we probably also want to do the same cleanup in those cases. The
    best way to deal with that is probably the "EXIT-CODE !" approach.

    Concerning the usual discussion about the name: I find that the system
    is left in the error case with an uncaught THROW in script-execution
    mode; in that case an exit code of 1 is returned by Gforth, so it's
    not sufficient for communicating more than a binary result to the
    calling script. But I have not used non-binary exit codes for
    non-Forth programs, either, and I do quite a bit of shell scripting.

    In any case, while we have (BYE), I don't use it in application
    programs.

    - anton
    --
    M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
    comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
    New standard: https://forth-standard.org/
    EuroForth 2024: https://euro.theforth.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anthony Howe@21:1/5 to Ruvim on Fri Nov 8 06:34:05 2024
    On 2024-11-07 17:04, Ruvim wrote:
    On 2024-11-07 22:50, Anthony Howe wrote:
    On 2024-11-07 06:56, Ruvim wrote:
    I would like to find a more appropriate name for this word than "bye- status".

    (bye) ( u -- )

    Seems apropos, short, to the point and indicative of an internal word.

    Yes, and because of the latter this name cannot be used for a standard word. Standard words are not internal words, but are part of the public interface.

    But the precedent for defining and exposing an internal word has been set in the
    standard with Locals `(local)`. So defining `(bye)` seems reasonable.

    What about the following options:

      badbye ( n -- never )
        - because it's probably not normal termination
        - if n is 0, then it's false-bad (i.e, good)

    `badbye` - did you have a bad breakup as a teen? If you're a JJ Abrams fan maybe why not `badrobot`.

      goodbye ( n -- never )
        - ironically when n is not zero

    Well I had suggested `bye-bye` and tossed the idea of `goodbye` cause is not so good.

      getout ( n -- never )
        - send control very far from here

    Sounds like something from a horror movie <deep sinister voice>get-out! get out of the house!</>

    Maybe borrow from non-english:

    `ciao` `sayonara` `fini`

    Maybe ask someone with young children and see what they come up with. Bet you get some "interesting" answers.

    SIGTERM is a good association with processes.

    Perhaps, SIGTERM can be send to another process too.

    That would probably something like kill(2), eg: kill(1234, SIGTERM)

    --
    Anthony C Howe
    achowe@snert.com BarricadeMX & Milters http://nanozen.snert.com/ http://software.snert.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to Ruvim on Fri Nov 8 13:21:44 2024
    Ruvim <ruvim.pinka@gmail.com> writes:
    On 2024-11-08 12:29, Anton Ertl wrote:
    mhx@iae.nl (mhx) writes:
    Same as remarked by minforth: there is a exit-handler chain in
    which the user can plug arbitrary routines.

    In Gforth BYE is a deferred word, with the intention that it can be
    extended with cleanup actions.

    The disadvantage of this approach in connection with the non-0 exit is
    that we probably also want to do the same cleanup in those cases. The
    best way to deal with that is probably the "EXIT-CODE !" approach.

    I think, this variable, if it is required, should be internal.

    For example:

    variable _system-exit-status 0 _system-exit-status !

    : kernel-bye ( -- never )
    ... \ other actions
    _system-exit-status @ (bye)
    ;

    defer bye ' kernel-bye is bye

    : bye-with-status ( n -- never )
    _system-exit-status ! bye
    ;

    Yes.

    Thus, the old interface is not changed. And `bye-with-status` also does
    the same cleanup sequence (if any).

    Which old interface?

    Concerning the usual discussion about the name: I find that the system
    is left in the error case with an uncaught THROW in script-execution
    mode; in that case an exit code of 1 is returned by Gforth, so it's
    not sufficient for communicating more than a binary result to the
    calling script. But I have not used non-binary exit codes for
    non-Forth programs, either, and I do quite a bit of shell scripting.

    Does it mean that "bye" and "bye-failure" is enough?

    It means that BYE and THROW (ABORT etc.) is enough. E.g., if I want
    to implement something like the program false:

    [/tmp:153395] cat >myfalse <<EOF
    #! /home/anton/gforth/gforth
    abort
    EOF
    [/tmp:153396] cat myfalse
    #! /home/anton/gforth/gforth
    abort
    [/tmp:153402] chmod +x myfalse
    [/tmp:153397] ./myfalse

    [/tmp:153398] echo $?
    255
    [/tmp:153399] false
    [/tmp:153400]

    One difference from the behaviour of false is, as you can see, that
    myfalse still produces a newline (probably coming from ABORT, because
    it works if I replace the ABORT with "255 (bye)". Maybe still
    something to work on.

    In any case, while we have (BYE), I don't use it in application
    programs.


    As an example, when a script is used in Make, it is important to return >nonzero exit status on error.

    Errors tend to result in uncaught THROWs, not in calls to (BYE). And
    these uncaught THROWs actually produce a nonzero exit status. They
    tend to also produce a useful error message without too much work:

    [/tmp:153406] gforth -e 's" /etc/passwd" slurp-file type bye' root:x:0:0:root:/root:/bin/bash
    ...
    [/tmp:153407] gforth -e 's" /typo/etc/passwd" slurp-file type bye'

    *OS command line*:-1: No such file or directory
    s" /typo/etc/passwd" >>>slurp-file<<< type bye
    Backtrace:
    $7FA065165980 throw
    [/tmp:153408] echo $?
    1

    - anton
    --
    M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
    comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
    New standard: https://forth-standard.org/
    EuroForth 2024: https://euro.theforth.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anthony Howe@21:1/5 to Ruvim on Fri Nov 8 10:10:16 2024
    On 2024-11-08 07:16, Ruvim wrote:
    But the precedent for defining and exposing an internal word has been set in >> the standard with Locals `(local)`.  So defining `(bye)` seems reasonable.

    `(local)` is a good example when a better names was not found. I'm not sure this
    form of naming should be used for standard words.

    Well that's a policy the committee will have set I assume.

    What about "die" ?  ;-)

    `die` works.

    It is used in 8th and in Perl.

    Oh how I wish Perl would truly die, but that is in the realm of pet peeves.

    BTW, the name "halt" for that is used in FreePascal. <https://www.freepascal.org/docs-html/rtl/system/halt.html>

    Erlang also has halt/1. Though as said before, "halt" might be confused with halt(1).

    Other, more technical variants:

      exit-process ( n -- never )

    Little wordy, but it is clear.

    Okay. What name to choose for the word that terminates the thread/task of the caller?

    Isn't this OT? Thought we're concerned with exit to host case?


    If we take "exit-process" to terminate the own process,
    then "exit-thread" or "exit-task" can be used for thread/task.

    Works for me and is clear as to what is ending.

    --
    Anthony C Howe
    achowe@snert.com BarricadeMX & Milters http://nanozen.snert.com/ http://software.snert.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to achowe@snert.com on Fri Nov 8 18:54:55 2024
    In article <vgj268$2p1e5$1@dont-email.me>,
    Anthony Howe <achowe@snert.com> wrote:
    On 2024-11-07 06:56, Ruvim wrote:
    I would like to find a more appropriate name for this word than "bye-status".

    (bye) ( u -- )

    Seems apropos, short, to the point and indicative of an internal word. Default
    can be defined to return to the host OS with an exit status `u`, but maybe be >replaced in (unhosted) environments to perform some sort of system reset, power
    cycle, or other implementation defined system reset.

    I agree that it is the politically correct definition.
    However the question was, is it worth it to standardise.
    The answer is of course: no.


    `terminate` is a good candidate, but it's unclear what it should terminate — a
    thread/task, or a process, or the own process, or the own thread.

    TERMINATE could have the same meaning as SIGTERM *:

    SIGTERM (Terminated)
    This signal is the default signal sent by kill(1) and represents a
    user or administrator request that a program shut down [normally].

    * Other signals result in abnormal termination.


    --
    Anthony C Howe
    achowe@snert.com BarricadeMX & Milters >http://nanozen.snert.com/ http://software.snert.com/

    Groetjes Albert
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@21:1/5 to albert@spenarnc.xs4all.nl on Fri Nov 8 20:12:15 2024
    On Fri, 8 Nov 2024 17:54:55 +0000, albert@spenarnc.xs4all.nl wrote:

    In article <vgj268$2p1e5$1@dont-email.me>,
    Anthony Howe <achowe@snert.com> wrote:
    On 2024-11-07 06:56, Ruvim wrote:
    I would like to find a more appropriate name for this word than
    "bye-status".

    (bye) ( u -- )

    Seems apropos, short, to the point and indicative of an internal word.
    Default
    can be defined to return to the host OS with an exit status `u`, but
    maybe be
    replaced in (unhosted) environments to perform some sort of system reset,
    power
    cycle, or other implementation defined system reset.

    I agree that it is the politically correct definition.
    However the question was, is it worth it to standardise.
    The answer is of course: no.

    If you are writing software that is to be maintained by other people
    (and by yourself) in the future, it is best to give the routines
    descriptive names. For example, FREE-ALLOCATED-OBJECTS or
    DISCONNECT-NETWORK or SHUTDOWN-POWER-SUPPLIES. Furthermore, such
    routines are different for every system, and in some desktop systems
    they do not even exist. In my opinion, standardisation in this area
    makes no sense at all.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)