So what shall we do with ANS CASE :)
YouTube offered this to me. Perhaps the world is catching on.
https://youtu.be/EumXak7TyQ0
YouTube offered this to me. Perhaps the world is catching on.
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.
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).
YouTube offered this to me. Perhaps the world is catching on.
So what shall we do with ANS CASE :)
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.
YouTube offered this to me. Perhaps the world is catching on.
https://youtu.be/EumXak7TyQ0
So what shall we do with ANS CASE :)
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.
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.
...
An IF-THEN statement contains an ELSE in only
20 - 25% of cases
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
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%
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% ?
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
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 daysthe 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
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.
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
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 20:17:20 |
Calls: | 9,487 |
Calls today: | 6 |
Files: | 13,617 |
Messages: | 6,121,093 |