Re: Average of a [stack]

Liste des GroupesRevenir à cl forth 
Sujet : Re: Average of a [stack]
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forth
Date : 14. May 2025, 12:45:49
Autres entêtes
Organisation : novaBBS
Message-ID : <2baacb6a260b68c4d1178a1a290b3ecc@www.novabbs.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Rocksolid Light
On Wed, 14 May 2025 9:17:10 +0000, Hans Bezemer wrote:

On 14-05-2025 09:07, ahmed wrote:
On Wed, 14 May 2025 5:51:35 +0000, anthk wrote:
>
On 2024-07-11, ahmed <melahi_ahmed@yahoo.fr> wrote:
Thanks for the explanation.
How can I get FOR and NEXT with MinForth? I have MF384.
>
Ahmed
>
In pforth (pfe), that's why I use to test code made for eforth:
>
: >MARK ( --A ) HERE 0 , ;
: AHEAD ( --A ) COMPILE branch >MARK ; IMMEDIATE
: AFT ( a --a A ) DROP [COMPILE] AHEAD [COMPILE] BEGIN SWAP ; IMMEDIATE
>
: FOR ( RUNTIME: N -- )
        COMPILE ABS  \ NO NEGATIVES
        COMPILE LIT 0 , COMPILE SWAP
        [COMPILE] ?DO ; IMMEDIATE
>
: NEXT
        COMPILE LIT -1 ,
        [COMPILE] +LOOP ; IMMEDIATE
>
Thanks.
>
I've already defined for and next in MinForth like this:
>
: (0) 0 ;
: (-1) -1 ;
: for_ postpone (0) postpone swap postpone ?do ; immediate
: _next postpone (-1) postpone +loop ; immediate
>
and here is an example of use:
>
: go_ 10 for_ i . _next ;
>
go_  10 9 8 7 6 5 4 3 2 1 0  ok
>
Well, it isn't standardized - so you can make it anything you want to. I
got two variants, the one I think it should be, and the one from eForth:
>
:macro for  >r begin r@ 0> while  ;
:macro next r> 1- >r repeat rdrop ;
>
eForth:
:macro for  >r begin ;
:macro next r@ 0> while r> 1- >r repeat rdrop ;
>
They *SEEM* almost identical, but they aren't. The eForth one performs
"the action" before the condition is tested, mine *AFTER* the condition
is tested.
>
Now - what do I expect when I issue a "10"? I expect a thing to be
performed ten times. No more, no less. And that's what mine gets. The
eForth one does not ten things, but eleven (including the zero). Also
note my version fixes another DO..LOOP problem - it bombs out when the
count is zero or less.
>
Finally, we all agree DO..LOOP is deeply flawed (it is) but we still
prefer to use it - preferably with loops with negative subscripts, or
garnishing it with horrors like UNLOOP and LEAVE (Hello! - it's a
*counted* loop. It should do as many times as I asked it to do initially
- not halfway change my mind saying "Oops - now I want you to quit
anyway").
>
In a 1000 line Forth program I use DO..LOOP 11 times - none with LEAVE
or UNLOOP. In another 500 line program, not at all. So if I had to
encode FOR..NEXT I wouldn't choose DO..LOOP - for obvious reasons.
>
Hans Bezemer
Thanks for the information and the calrifications.
I recopied it to gforth (using postpone) like this and it works.
: for_ postpone >r postpone begin postpone r@ postpone 0> postpone while
; immediate   ok
: _next postpone r> postpone 1- postpone >r postpone repeat postpone
rdrop ; immediate  ok
: go for_ i . _next ;  ok
10 go 10 9 8 7 6 5 4 3 2 1  ok
0 go  ok
1 go 1  ok
Ahmed
--

Date Sujet#  Auteur
10 Jul 24 * Re: Average of a [stack]28Buzz McCool
11 Jul 24 +* Re: Average of a [stack]10dxf
11 Jul 24 i`* Re: Average of a [stack]9Buzz McCool
12 Jul 24 i `* Re: Average of a [stack]8dxf
12 Jul 24 i  `* Re: Average of a [stack]7Buzz McCool
15 Jul 24 i   `* Re: Average of a [stack]6Buzz McCool
18 Jul 24 i    `* Re: Average of a [stack]5minforth
18 Jul 24 i     `* Re: Average of a [stack]4Buzz McCool
18 Jul 24 i      +- Re: Average of a [stack]1minforth
19 Jul 24 i      `* Re: Average of a [stack]2dxf
19 Jul 24 i       `- Re: Average of a [stack]1Buzz McCool
11 Jul 24 +* Re: Average of a [stack]16dxf
11 Jul 24 i`* Re: Average of a [stack]15ahmed
11 Jul 24 i `* Re: Average of a [stack]14ahmed
11 Jul 24 i  `* Re: Average of a [stack]13minforth
11 Jul 24 i   `* Re: Average of a [stack]12ahmed
11 Jul 24 i    +- Re: Average of a [stack]1ahmed
11 Jul 24 i    `* Re: Average of a [stack]10minforth
11 Jul 24 i     `* Re: Average of a [stack]9ahmed
11 Jul 24 i      +- Re: Average of a [stack]1minforth
14 May 25 i      `* Re: Average of a [stack]7anthk
14 May 25 i       `* Re: Average of a [stack]6ahmed
14 May 25 i        +- Re: Average of a [stack]1ahmed
15 May 25 i        `* Re: Average of a [stack]4dxf
15 May 25 i         +* Re: Average of a [stack]2Hans Bezemer
15 May 25 i         i`- Re: Average of a [stack]1dxf
15 May 25 i         `- Re: Average of a [stack]1Hans Bezemer
12 Jul 24 `- Re: Average of a [stack]1Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal