• Re: Why I Don't Use Else When Programming

    From jan Coombs@21:1/5 to dxf on Sat Sep 23 11:09:33 2023
    On Sat, 23 Sep 2023 19:33:05 +1000
    dxf <dxforth@gmail.com> wrote:

    So what shall we do with ANS CASE :)

    Ideally, ignore if you do not need CASE, else
    conform with ANS, else use a different name.

    Jan Coombs
    --

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxf@21:1/5 to All on Sat Sep 23 19:33:05 2023
    YouTube offered this to me. Perhaps the world is catching on.

    https://youtu.be/EumXak7TyQ0

    So what shall we do with ANS CASE :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Sat Sep 23 03:15:55 2023
    YouTube offered this to me. Perhaps the world is catching on.

    https://youtu.be/EumXak7TyQ0

    This has been already described years ago in „Thinking Forth”
    („ATM example”, chapter 8).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Brian Fox@21:1/5 to dxf on Sat Sep 23 06:44:03 2023
    On Saturday, September 23, 2023 at 5:33:09 AM UTC-4, dxf wrote:
    YouTube offered this to me. Perhaps the world is catching on.

    We must have similar profiles. I saw it yesterday as well.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxf@21:1/5 to jan Coombs on Sun Sep 24 17:08:02 2023
    On 23/09/2023 8:09 pm, jan Coombs wrote:
    On Sat, 23 Sep 2023 19:33:05 +1000
    dxf <dxforth@gmail.com> wrote:

    So what shall we do with ANS CASE :)

    Ideally, ignore if you do not need CASE, else
    conform with ANS, else use a different name.

    I suspect most find 'case' too useful to ignore. I provide
    ANS as a compatibility add-on.

    Mostly OF suffices (applying the don't use ELSE paradigm).
    Should I need a common-exit case, I have is COND CONT.
    From the latter I define the compatibility words:

    AKA COND CASE
    AKA ELSE ENDOF
    : ENDCASE POSTPONE DROP POSTPONE CONT ; IMMEDIATE

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxf@21:1/5 to Zbig on Sun Sep 24 17:20:38 2023
    On 23/09/2023 8:15 pm, Zbig wrote:
    YouTube offered this to me. Perhaps the world is catching on.

    https://youtu.be/EumXak7TyQ0

    This has been already described years ago in „Thinking Forth”
    („ATM example”, chapter 8).

    Yes - and little has changed since :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hans Bezemer@21:1/5 to dxf on Sun Sep 24 07:48:21 2023
    On Saturday, September 23, 2023 at 11:33:09 AM UTC+2, dxf wrote:
    YouTube offered this to me. Perhaps the world is catching on.
    So what shall we do with ANS CASE :)

    It's nothing new - but note it's also a paradigm shift. In the old days the world wanted
    a single return from a function - which was logical in a sense, because long functions
    were still very much a reality. Using too many exit points was waiting for an accident to
    happen. Maybe it was also fashionable to write long functions to minimize function call
    overhead. Especially on older processors it's not insignificant - building a stack frame,
    discarding it on exit.. you catch my drift.

    I quickly found out all that is not much of an issue with Forth, because small functions
    (words) were the paradigm there (read "Thinking Forth"). So I quickly switched to multiple
    exits.

    On 4tH this was amplified by the introduction of the optimizer. Using ;THEN instead of
    ELSE provided much tighter code, because it discarded superfluous jumps. So if there
    was nothing after a THEN to execute, ELSE could be replaced by a ;THEN quite easily.

    BTW, if you got an ELSE clause and the IF requires a 0= you can further simplify by
    switching the IF and ELSE clauses, so there is no need for 0= anymore.

    Anyways, you see that the C-like world is moving to shorter functions, because they're
    much easier to control. Of course, there are still exceptions - e.g. when speed is the prime
    directive. I wouldn't like to break up my VM code in smaller chunks, for example. Worse,
    I'm inlining a *lot* there for the same reason.

    I don't know how other Forths are in this regard, but on smaller tables CASE..ENDCASE is
    significantly faster than any other technique - with the exception of direct indexed access.
    On smaller tables it even easily beats a binary search. So for that reason - and that reason
    alone - I'm keeping that construct in.

    Hans Bezemer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxf@21:1/5 to Hans Bezemer on Mon Sep 25 12:49:09 2023
    On 25/09/2023 12:48 am, Hans Bezemer wrote:
    On Saturday, September 23, 2023 at 11:33:09 AM UTC+2, dxf wrote:
    YouTube offered this to me. Perhaps the world is catching on.
    So what shall we do with ANS CASE :)

    It's nothing new - but note it's also a paradigm shift. In the old days the world wanted
    a single return from a function - which was logical in a sense, because long functions
    were still very much a reality. Using too many exit points was waiting for an accident to
    happen. Maybe it was also fashionable to write long functions to minimize function call
    overhead. Especially on older processors it's not insignificant - building a stack frame,
    discarding it on exit.. you catch my drift.

    There are reasons for continuing to use ELSE but how did we get ELSE ? ELSE is a
    logical complement to IF and I suspect that's why every language has it. Having
    ELSE, it has become a habit - one whose cost we've not really considered before.

    I quickly found out all that is not much of an issue with Forth, because small functions
    (words) were the paradigm there (read "Thinking Forth"). So I quickly switched to multiple
    exits.

    On 4tH this was amplified by the introduction of the optimizer. Using ;THEN instead of
    ELSE provided much tighter code, because it discarded superfluous jumps. So if there
    was nothing after a THEN to execute, ELSE could be replaced by a ;THEN quite easily.

    BTW, if you got an ELSE clause and the IF requires a 0= you can further simplify by
    switching the IF and ELSE clauses, so there is no need for 0= anymore.

    Anyways, you see that the C-like world is moving to shorter functions, because they're
    much easier to control. Of course, there are still exceptions - e.g. when speed is the prime
    directive. I wouldn't like to break up my VM code in smaller chunks, for example. Worse,
    I'm inlining a *lot* there for the same reason.

    I don't know how other Forths are in this regard, but on smaller tables CASE..ENDCASE is
    significantly faster than any other technique - with the exception of direct indexed access.
    On smaller tables it even easily beats a binary search. So for that reason - and that reason
    alone - I'm keeping that construct in.

    I agree. For me it's the syntax rather than the mechanism that irritates.
    ELSE (aka ENDOF) is built into the syntax and the user is stuck with it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From NN@21:1/5 to dxf on Fri Sep 29 08:01:26 2023
    On Saturday, 23 September 2023 at 10:33:09 UTC+1, dxf wrote:
    YouTube offered this to me. Perhaps the world is catching on.

    https://youtu.be/EumXak7TyQ0

    So what shall we do with ANS CASE :)


    https://youtu.be/SFv8Wm2HdNM?si=Xxcw7yy1zZEg_aUk

    You can skip to 'the nesting structure' if you dont want to watch the whole video

    Its a shame we never get to hear back from the youtubers if they continued to believe and practice what they preached or whether they went back to their old ways after say 5 years or 10 years.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to All on Fri Sep 29 12:28:58 2023
    Statistics from the iForth distribution.

    Searching for: IF ( examples, 6908 files )
    Found 37736 occurrence(s) in 1300 file(s), 957 ms
    Searching for: ELSE ( examples, 6908 files )
    Found 7010 occurrence(s) in 1028 file(s), 962 ms

    Searching for: IF ( include, 1183 files )
    Found 8241 occurrence(s) in 324 file(s), 233 ms
    Searching for: ELSE ( include, 1183 files )
    Found 2393 occurrence(s) in 296 file(s), 240 ms

    An IF-THEN statement contains and ELSE in 20 - 25% of cases.

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxf@21:1/5 to All on Sat Sep 30 11:21:42 2023
    On 30/09/2023 1:01 am, NN wrote:
    On Saturday, 23 September 2023 at 10:33:09 UTC+1, dxf wrote:
    YouTube offered this to me. Perhaps the world is catching on.

    https://youtu.be/EumXak7TyQ0

    So what shall we do with ANS CASE :)


    https://youtu.be/SFv8Wm2HdNM?si=Xxcw7yy1zZEg_aUk

    You can skip to 'the nesting structure' if you dont want to watch the whole video

    Its a shame we never get to hear back from the youtubers if they continued to believe and practice what they preached or whether they went back to their old ways after say 5 years or 10 years.

    If a serial youtuber, it may be more about the presentation than conviction?

    Among the 'conviction' topics I've written about:

    http://dxforth.mirrors.minimaltype.com/forth.html

    REPRESENT/FPOUT, BETWEEN, ALLOT, UNNEST, END I still embrace.

    The most problematic of which was ALLOT as it breaks standard code.

    Extended control-flow I never had much use for again and is now a
    loadable extension.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to All on Fri Sep 29 23:16:22 2023
    Statistics from the iForth distribution.

    Searching for: IF ( examples, 6908 files )
    Found 37736 occurrence(s) in 1300 file(s), 957 ms
    Searching for: ELSE ( examples, 6908 files )
    Found 7010 occurrence(s) in 1028 file(s), 962 ms

    Searching for: IF ( include, 1183 files )
    Found 8241 occurrence(s) in 324 file(s), 233 ms
    Searching for: ELSE ( include, 1183 files )
    Found 2393 occurrence(s) in 296 file(s), 240 ms

    An IF-THEN statement contains an ELSE in only
    20 - 25% of cases, while an IF is used in roughly
    one out of four programs.

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to Marcel Hendrix on Sat Sep 30 07:00:48 2023
    Marcel Hendrix <mhx@iae.nl> writes:
    Statistics from the iForth distribution.

    Searching for: IF ( examples, 6908 files )
    Found 37736 occurrence(s) in 1300 file(s), 957 ms
    Searching for: ELSE ( examples, 6908 files )
    Found 7010 occurrence(s) in 1028 file(s), 962 ms

    Searching for: IF ( include, 1183 files )
    Found 8241 occurrence(s) in 324 file(s), 233 ms
    Searching for: ELSE ( include, 1183 files )
    Found 2393 occurrence(s) in 296 file(s), 240 ms

    An IF-THEN statement contains and ELSE in 20 - 25% of cases.

    In the Gforth image there are 917 IFs and 347 ELSEs (38%).

    - 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 dxf@21:1/5 to Marcel Hendrix on Sat Sep 30 18:17:50 2023
    On 30/09/2023 4:16 pm, Marcel Hendrix wrote:
    ...
    An IF-THEN statement contains an ELSE in only
    20 - 25% of cases

    Only? It seems you went out of your way :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to Anton Ertl on Sat Sep 30 11:54:23 2023
    In article <2023Sep30.090048@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    Marcel Hendrix <mhx@iae.nl> writes:
    Statistics from the iForth distribution.

    Searching for: IF ( examples, 6908 files )
    Found 37736 occurrence(s) in 1300 file(s), 957 ms
    Searching for: ELSE ( examples, 6908 files )
    Found 7010 occurrence(s) in 1028 file(s), 962 ms

    Searching for: IF ( include, 1183 files )
    Found 8241 occurrence(s) in 324 file(s), 233 ms
    Searching for: ELSE ( include, 1183 files )
    Found 2393 occurrence(s) in 296 file(s), 240 ms

    An IF-THEN statement contains and ELSE in 20 - 25% of cases.

    In the Gforth image there are 917 IFs and 347 ELSEs (38%).

    To complete the statistics ciforth 44 IF and 14 ELSE.


    - anton

    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 spinning. - the Wise from Antrim -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ruvim@21:1/5 to Marcel Hendrix on Sat Sep 30 10:26:32 2023
    On 2023-09-29 19:28, Marcel Hendrix wrote:
    Statistics from the iForth distribution.

    Searching for: IF ( examples, 6908 files )
    Found 37736 occurrence(s) in 1300 file(s), 957 ms
    Searching for: ELSE ( examples, 6908 files )
    Found 7010 occurrence(s) in 1028 file(s), 962 ms

    Searching for: IF ( include, 1183 files )
    Found 8241 occurrence(s) in 324 file(s), 233 ms
    Searching for: ELSE ( include, 1183 files )
    Found 2393 occurrence(s) in 296 file(s), 240 ms

    An IF-THEN statement contains and ELSE in 20 - 25% of cases.



    In the SP-Forth/4 distribution (all the repository, many authors):
    Search for " IF\b"
    11205 matches
    1263 files contained matches
    2421 files searched
    Search for " ELSE\b"
    3868 matches
    853 files contained matches
    2421 files searched
    -- 35%

    In the sources of SP-Forth/4 only
    Search for " IF\b"
    1301 matches
    51 files contained matches
    85 files searched
    Search for " ELSE\b"
    184 matches
    40 files contained matches
    85 files searched
    -- 14%



    --
    Ruvim

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to Ruvim on Sat Sep 30 04:46:26 2023
    On Saturday, September 30, 2023 at 12:26:39 PM UTC+2, Ruvim wrote:
    [..]
    In the SP-Forth/4 distribution (all the repository, many authors):
    Search for " IF\b"
    11205 matches
    1263 files contained matches
    2421 files searched
    Search for " ELSE\b"
    3868 matches
    853 files contained matches
    2421 files searched
    -- 35%

    In the sources of SP-Forth/4 only
    Search for " IF\b"
    1301 matches
    51 files contained matches
    85 files searched
    Search for " ELSE\b"
    184 matches
    40 files contained matches
    85 files searched
    -- 14%

    Shouldn't that be 65% and 86% ?

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ruvim@21:1/5 to Marcel Hendrix on Sat Sep 30 21:26:33 2023
    On 2023-09-30 11:46, Marcel Hendrix wrote:
    On Saturday, September 30, 2023 at 12:26:39 PM UTC+2, Ruvim wrote:
    [..]
    In the SP-Forth/4 distribution (all the repository, many authors):
    Search for " IF\b"
    11205 matches
    1263 files contained matches
    2421 files searched
    Search for " ELSE\b"
    3868 matches
    853 files contained matches
    2421 files searched
    -- 35%

    In the sources of SP-Forth/4 only
    Search for " IF\b"
    1301 matches
    51 files contained matches
    85 files searched
    Search for " ELSE\b"
    184 matches
    40 files contained matches
    85 files searched
    -- 14%

    Shouldn't that be 65% and 86% ?

    I consider the number of matches (not the number of files) in each of
    two groups of files. The second group (85 files) is a subset of the
    first group (2421 files). The number of files are left for reference only.

    Also, I assume that when "ELSE" is used, "IF" is used too.
    Thus, the percentage shows the fraction of IF THEN that is used with ELSE.

    3868/11205 = 0.35 (in the first group)
    184/1301 = 0.14 (in the second group)


    --
    Ruvim

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From S Jack@21:1/5 to Hans Bezemer on Sat Sep 30 15:45:02 2023
    On Sunday, September 24, 2023 at 9:48:24 AM UTC-5, Hans Bezemer wrote:
    It's nothing new - but note it's also a paradigm shift. In the old days the world wanted
    a single return from a function - which was logical in a sense, because long functions

    A single exit helps if a breakpoint or some analysis routine
    is wanted to decorate a word's ending.
    --
    me

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to sdwjack69@gmail.com on Sun Oct 1 02:11:07 2023
    In article <30e85f38-df81-477a-91db-96304b5f81b7n@googlegroups.com>,
    S Jack <sdwjack69@gmail.com> wrote:
    On Sunday, September 24, 2023 at 9:48:24 AM UTC-5, Hans Bezemer wrote:
    It's nothing new - but note it's also a paradigm shift. In the old days
    the world wanted
    a single return from a function - which was logical in a sense, because >long functions

    A single exit helps if a breakpoint or some analysis routine
    is wanted to decorate a word's ending.

    The decorator in ciforth doesn't need a single exit for `example.

    WANT { decorated CO
    { .S CO .S } 'example decorated

    This prints the stack before and after example.

    --
    me

    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 spinning. - the Wise from Antrim -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From S Jack@21:1/5 to All on Sat Sep 30 16:43:21 2023
    On Saturday, September 30, 2023 at 5:45:04 PM UTC-5, S Jack wrote:

    I put exits in routines that don't need them, e.g. ABORT,
    and I have a redundant exit for use with shortcuts.
    Redundant and superfluous code, what horrors!
    Well, the de-compiler knows to keep going until SEMIS is
    found.
    --
    me

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxf@21:1/5 to S Jack on Sun Oct 1 13:42:12 2023
    On 1/10/2023 10:43 am, S Jack wrote:
    On Saturday, September 30, 2023 at 5:45:04 PM UTC-5, S Jack wrote:

    I put exits in routines that don't need them, e.g. ABORT,
    and I have a redundant exit for use with shortcuts.
    Redundant and superfluous code, what horrors!
    Well, the de-compiler knows to keep going until SEMIS is
    found.

    If Forth is as 'close to the metal' as we like to claim, there
    should be no need to seek assurances from de-compilers.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From S Jack@21:1/5 to dxf on Sun Oct 1 09:02:25 2023
    On Saturday, September 30, 2023 at 9:42:15 PM UTC-5, dxf wrote:

    If Forth is as 'close to the metal' as we like to claim, there
    should be no need to seek assurances from de-compilers.

    Seem to recall that it also helped with compiling words that move pre-compiled code into a definition instead of compiling source into the definition.
    --
    me

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to sdwjack69@gmail.com on Mon Oct 2 11:55:15 2023
    In article <20e3626c-b571-4be6-a002-5002517bcd18n@googlegroups.com>,
    S Jack <sdwjack69@gmail.com> wrote:
    On Saturday, September 30, 2023 at 9:42:15 PM UTC-5, dxf wrote:

    If Forth is as 'close to the metal' as we like to claim, there
    should be no need to seek assurances from de-compilers.

    Seem to recall that it also helped with compiling words that move pre-compiled >code into a definition instead of compiling source into the definition.

    No need to be categoric about this. de-compilers come in handy for
    a lot of purposes.

    Remember the macro solution for the magic hexagon?
    It is interesting to look at the decompilation that finally comes out.

    I use the decompilation of my ciforth to compare with previous version,
    an extra precaution to detect mistakes.

    --
    me

    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 spinning. - the Wise from Antrim -

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