Avoid treating the stack as an array [Re: "Back & Forth" is back!]

Liste des GroupesRevenir à cl forth 
Sujet : Avoid treating the stack as an array [Re: "Back & Forth" is back!]
De : buzz_mccool (at) *nospam* yahoo.com (Buzz McCool)
Groupes : comp.lang.forth
Date : 30. Aug 2024, 17:04:58
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vasqjd$icjm$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 8/10/2024 3:57 AM, Hans Bezemer wrote:
After explaining why Forth is so hard, I'm explaining what reasons there could be to use it. With a little personal journey put in as a side note.
 https://www.youtube.com/watch?v=MXKZPGzlx14
I looked through a few of these videos and found them interesting, thank you Hans for going to the trouble of making them.
I found Hans' recommendation on one of the videos (if I'm paraphrasing it correctly) to avoid using the stack for more than two or three values as treating the stack as an array makes for incomprehensible code, enlightening.
I am trying to follow this recommendation, but am running into trouble when trying to pass parameters into a loop. I'm trying to avoid using the stack as a large array but what I came up by injecting a parameter with a variable doesn't seem right.
Does anyone have suggestions on a better approach when you have several parameters and loop counts to deal with?
(Trivial Example)
: AreaOfCir 2.0e f** pi f* ;     \ w/ radius on stack,
                                  \ compute area (radius^2 * pi)
: VolOfCyl AreaOfCir f* ;        \ w/ height & radius on stack,
                                  \ compute vol (height * area)
1.0e AreaOfCir fe.
3.1416E0
2.0e 1.0e VolOfCyl fe.
6.2832E0
fvariable radius       \ create a floating point variable
1.0e radius f!         \ store 1.0 into radius
radius f@ fe.          \ fetch and print radius
1.0000E0
: CylVolLoop
cr ." Radius " radius f@ fe. \ print a new line and then fetch and print radius
1                     \ start counter from a cyl height of 1
begin dup 20 <=       \ duplicate counter to see if counter <= end value
while                 \ while true (i.e. counter is <= to 20)
dup                   \ duplicate counter
s>f                   \ convert counter (height) to floating point
fdup                  \ duplicate height to print and use to compute vol
cr ." Height " fe.    \ print a new line and then print height
radius f@             \ fetch radius
VolOfCyl              \ compute volume
." Volume " fe.       \ print volume
1 +                   \ add one to counter
repeat                \ repeat the test at the "begin" word
drop ;                \ remove the leftover loop counter value
CylVolLoop    \ Execute CylVolLoop word
Radius 1.0000E0
Height 1.0000E0 Volume 3.1416E0
Height 2.0000E0 Volume 6.2832E0
...
Height 19.000E0 Volume 59.690E0
Height 20.000E0 Volume 62.832E0

Date Sujet#  Auteur
30 Aug 24 * Avoid treating the stack as an array [Re: "Back & Forth" is back!]142Buzz McCool
30 Aug 24 +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]9minforth
31 Aug 24 i+- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1BuzzMcCool
2 Sep 24 i+* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]4Buzz McCool
3 Sep 24 ii`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]3dxf
3 Sep 24 ii `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]2Buzz McCool
3 Sep 24 ii  `- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1dxf
11 Sep 24 i+* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]2minforth
11 Sep 24 ii`- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1Hans Bezemer
12 Sep 24 i`- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1dxf
31 Aug 24 `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]132dxf
31 Aug 24  `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]131BuzzMcCool
6 Sep 24   `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]130Buzz McCool
7 Sep 24    +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]123Hans Bezemer
10 Sep 24    i`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]122Paul Rubin
10 Sep 24    i +- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1dxf
11 Sep 24    i +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]117dxf
11 Sep 24    i i`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]116dxf
12 Sep 24    i i `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]115Paul Rubin
12 Sep 24    i i  +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]98dxf
12 Sep 24    i i  i+* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]3minforth
12 Sep 24    i i  ii`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]2mhx
12 Sep 24    i i  ii `- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1minforth
12 Sep 24    i i  i+* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]57Anton Ertl
13 Sep 24    i i  ii`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]56dxf
13 Sep 24    i i  ii `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]55minforth
13 Sep 24    i i  ii  `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]54dxf
13 Sep 24    i i  ii   +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]10Paul Rubin
13 Sep 24    i i  ii   i+* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]2Jan Coombs
13 Sep 24    i i  ii   ii`- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1Anton Ertl
13 Sep 24    i i  ii   i`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]7dxf
14 Sep 24    i i  ii   i `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]6Paul Rubin
14 Sep 24    i i  ii   i  `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]5dxf
14 Sep 24    i i  ii   i   `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]4Paul Rubin
15 Sep 24    i i  ii   i    `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]3dxf
15 Sep 24    i i  ii   i     `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]2Paul Rubin
16 Sep 24    i i  ii   i      `- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1dxf
13 Sep 24    i i  ii   +- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1albert
13 Sep 24    i i  ii   `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]42Anton Ertl
14 Sep 24    i i  ii    `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]41dxf
14 Sep 24    i i  ii     +- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1minforth
14 Sep 24    i i  ii     `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]39Anton Ertl
14 Sep 24    i i  ii      +- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1dxf
15 Sep 24    i i  ii      `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]37Stephen Pelc
15 Sep 24    i i  ii       `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]36Anton Ertl
15 Sep 24    i i  ii        +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]9Stephen Pelc
15 Sep 24    i i  ii        i+* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]7Paul Rubin
16 Sep 24    i i  ii        ii`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]6Stephen Pelc
16 Sep 24    i i  ii        ii +- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1minforth
16 Sep 24    i i  ii        ii `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]4Anton Ertl
16 Sep 24    i i  ii        ii  `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]3mhx
16 Sep 24    i i  ii        ii   `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]2Anton Ertl
17 Sep 24    i i  ii        ii    `- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1mhx
16 Sep 24    i i  ii        i`- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1Anton Ertl
27 Sep 24    i i  ii        `* value-flavoured structures (was: Avoid treating the stack as an array)26Ruvim
27 Sep 24    i i  ii         +* Re: value-flavoured structures15minforth
27 Sep 24    i i  ii         i+- Re: value-flavoured structures1mhx
27 Sep 24    i i  ii         i`* Re: value-flavoured structures13Ruvim
27 Sep 24    i i  ii         i `* Re: value-flavoured structures12minforth
27 Sep 24    i i  ii         i  +* Re: value-flavoured structures8Ruvim
28 Sep 24    i i  ii         i  i+* Re: value-flavoured structures6Paul Rubin
28 Sep 24    i i  ii         i  ii+* Re: value-flavoured structures2dxf
28 Sep 24    i i  ii         i  iii`- Re: value-flavoured structures1Paul Rubin
28 Sep 24    i i  ii         i  ii`* Re: value-flavoured structures3albert
28 Sep 24    i i  ii         i  ii `* Re: value-flavoured structures2Paul Rubin
28 Sep 24    i i  ii         i  ii  `- Re: value-flavoured structures1Paul Rubin
28 Sep 24    i i  ii         i  i`- Re: value-flavoured structures1dxf
3 Oct 24    i i  ii         i  `* Re: value-flavoured structures3Anton Ertl
4 Oct 24    i i  ii         i   `* Re: value-flavoured structures2dxf
4 Oct 24    i i  ii         i    `- Re: value-flavoured structures1albert
3 Oct 24    i i  ii         `* Re: value-flavoured structures (was: Avoid treating the stack as an array)10Anton Ertl
4 Oct 24    i i  ii          `* Re: value-flavoured structures9Ruvim
4 Oct 24    i i  ii           `* Re: value-flavoured structures8Anton Ertl
4 Oct 24    i i  ii            `* Re: value-flavoured structures7Ruvim
4 Oct 24    i i  ii             `* Re: value-flavoured structures6Anton Ertl
5 Oct 24    i i  ii              `* Re: value-flavoured structures5Ruvim
5 Oct 24    i i  ii               `* Re: value-flavoured structures4Anton Ertl
6 Oct 24    i i  ii                +- value-flavoured properties of a word (was: value-flavoured structures)1Ruvim
6 Oct 24    i i  ii                +- value-flavoured approach (was: value-flavoured structures)1Ruvim
6 Oct 24    i i  ii                `- value-flavoured approach in API (was: value-flavoured structures)1Ruvim
14 Sep 24    i i  i`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]37Anton Ertl
14 Sep 24    i i  i +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]34Ahmed
14 Sep 24    i i  i i+* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]32Anton Ertl
14 Sep 24    i i  i ii`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]31Ahmed
14 Sep 24    i i  i ii +- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1Ahmed
14 Sep 24    i i  i ii +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]7Ahmed
14 Sep 24    i i  i ii i`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]6mhx
14 Sep 24    i i  i ii i +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]4Ahmed
15 Sep 24    i i  i ii i i`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]3minforth
15 Sep 24    i i  i ii i i `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]2Ahmed
15 Sep 24    i i  i ii i i  `- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1Ahmed
15 Sep 24    i i  i ii i `- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1albert
15 Sep 24    i i  i ii `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]22dxf
15 Sep 24    i i  i ii  +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]16Ahmed
15 Sep 24    i i  i ii  i`* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]15mhx
15 Sep 24    i i  i ii  i `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]14ahmed
16 Sep 24    i i  i ii  i  `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]13Ahmed
16 Sep 24    i i  i ii  i   `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]12mhx
16 Sep 24    i i  i ii  i    +- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1Ahmed
16 Sep 24    i i  i ii  i    +* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]3dxf
16 Sep 24    i i  i ii  i    i+- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1Ahmed
16 Sep 24    i i  i ii  i    i`- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1mhx
16 Sep 24    i i  i ii  i    `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]7Paul Rubin
15 Sep 24    i i  i ii  `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]5Paul Rubin
15 Sep 24    i i  i i`- Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]1albert
15 Sep 24    i i  i `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]2dxf
12 Sep 24    i i  `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]16Anton Ertl
11 Sep 24    i `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]3Hans Bezemer
8 Sep 24    `* Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]6Stephen Pelc

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal