• Re: Resolving multiple THENs

    From Anton Ertl@21:1/5 to dxf on Mon Jan 15 08:01:26 2024
    dxf <dxforth@gmail.com> writes:
    Forth has never really tackled resolving arbitrary multiple THENs - other than >in the limited context of CASE.

    Maybe that's why extending CASE has found adoption beyond the original
    source, a rarity in the NIH-dominated Forth circles in this century.

    COND
    IF ... ELSE ...
    IF ... ELSE ...
    IF ... ELSE ...
    CONT

    CASE
    ?OF ... ENDOF
    ... ?OF ... ENDOF
    ... ?OF ... ENDOF
    ...
    0 ENDCASE

    COND
    BEGIN
    WHILE ...
    WHILE ...
    WHILE ...
    AGAIN
    CONT

    CASE
    0= ?OF ENDOF
    ... 0= ?OF ENDOF
    ... 0= ?OF ENDOF
    ...
    NEXT-CASE

    Supported both in VFX (where it originated) and in Gforth.

    - 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 2023: https://euro.theforth.net/2023

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to dxf on Tue Jan 16 08:49:38 2024
    dxf <dxforth@gmail.com> writes:
    On 15/01/2024 7:01 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    Forth has never really tackled resolving arbitrary multiple THENs - other than
    in the limited context of CASE.

    Maybe that's why extending CASE has found adoption beyond the original
    source, a rarity in the NIH-dominated Forth circles in this century.
    ...
    Supported both in VFX (where it originated) and in Gforth.

    Why extend CASE ?

    Why not? We already have Eaker's CASE. Each step in extening it adds
    useful functionality:

    ?OF turns CASE into a general conditional control structure.

    NEXT-CASE allows extending that functionality to loops.

    CONTOF (Gforth-only for now) allows implementing loops like those
    written with the "do" command of the guarded-command language;
    alternatively, one can see it as extending OF/?OF with a looping
    variant like NEXT-CASE extended CASE with looping.

    - 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 2023: https://euro.theforth.net/2023

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to dxforth@gmail.com on Tue Jan 16 13:10:16 2024
    In article <uo5ltg$1c7te$1@dont-email.me>, dxf <dxforth@gmail.com> wrote:
    On 16/01/2024 7:49 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 15/01/2024 7:01 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    Forth has never really tackled resolving arbitrary multiple THENs - >other than
    in the limited context of CASE.

    Maybe that's why extending CASE has found adoption beyond the original >>>> source, a rarity in the NIH-dominated Forth circles in this century.
    ...
    Supported both in VFX (where it originated) and in Gforth.

    Why extend CASE ?

    Why not? We already have Eaker's CASE. Each step in extening it adds
    useful functionality:

    ?OF turns CASE into a general conditional control structure.

    Forth has IF for that. Adding words to replicate functionality
    that already exists is an unnecessary duplication.

    NEXT-CASE allows extending that functionality to loops.

    Forth has BEGIN AGAIN. No need to duplicate it.

    CONTOF (Gforth-only for now) allows implementing loops like those
    written with the "do" command of the guarded-command language;
    alternatively, one can see it as extending OF/?OF with a looping
    variant like NEXT-CASE extended CASE with looping.

    Wil Baden maintained Forth's control structures were sufficient.
    Sure enough I was able to replicate your CONTOF examples using
    regular forth at a similar level of complexity.

    I agree with Will.
    Anton Ertl had me to reconsider where I used CASE.
    Sure enough CASE is obscure, and I detected a long standing
    bug in a default case. That would never happen if I
    had used IF ELSE THEN .
    (The code was original from Marcel Hendrix, and I got confused
    converting the code for the default case
    DUP ABORT" something wrong"
    ).

    :I OF OVER = IF DROP ;
    :I ENDCASE DROP THENS ;

    Groetjes Albert
    --
    Don't praise the day before the evening. One swallow doesn't make spring.
    You must not say "hey" before you have crossed the bridge. Don't sell the
    hide of the bear until you shot it. Better one bird in the hand than ten in
    the air. First gain is a cat purring. - the Wise from Antrim -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to dxf on Tue Jan 16 16:01:07 2024
    dxf <dxforth@gmail.com> writes:
    On 16/01/2024 7:49 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 15/01/2024 7:01 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    Forth has never really tackled resolving arbitrary multiple THENs - other than
    in the limited context of CASE.
    ...
    Wil Baden maintained Forth's control structures were sufficient.

    Actually, Wil Baden showed that, with the seven words IF AHEAD THEN
    BEGIN AGAIN UNTIL CS-ROLL one can construct all control structures
    that one can construct with goto and conditional goto and labels.

    And yet we write

    begin ... while ... repeat

    instead of the "sufficient"

    begin ... if [ 1 cs-roll ] ... again then

    And yet you proposed to introduce COND ... CONT for "resolving
    arbitrary multiple THENs", which "Forth has never really tackled".

    Sure enough I was able to replicate your CONTOF examples using
    regular forth at a similar level of complexity.

    Certainly one can do so, and if you prefer to do so, that's fine with
    me. However, I find it easier to use the extended CASE for writing
    definitions where several cases have to be considered.

    - 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 2023: https://euro.theforth.net/2023

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