Deutsch   English   Français   Italiano  
<048828e75f8e839eb96b9334b2604c0cda8e8d8a@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: dxf <dxforth@gmail.com>
Newsgroups: comp.lang.forth
Subject: Re: Average of a [stack]
Date: Thu, 15 May 2025 10:51:26 +1000
Organization: i2pn2 (i2pn.org)
Message-ID: <048828e75f8e839eb96b9334b2604c0cda8e8d8a@i2pn2.org>
References: <v3raig$1bhkt$1@dont-email.me>
 <1ae05d1531d54df162c500815909ee37@www.novabbs.com>
 <v6n0pr$2363u$1@dont-email.me> <668f55eb$1@news.ausics.net>
 <8e8cfdb3c12f69e3a540a2817fdf8a48@www.novabbs.com>
 <6cb6b7766253730ea2f384fe48bc77c9@www.novabbs.com>
 <0745dbc99527d05661cd2fec5431980c@www.novabbs.com>
 <bc0623489b27ee52a13215b1a3c64360@www.novabbs.com>
 <e548140694f740bb847f686d6f8db3d3@www.novabbs.com>
 <6707ff1c65be5addceaddaab211099cc@www.novabbs.com>
 <46650539943a987516281bb1aaa2b8bf@www.novabbs.com>
 <slrn1027f7f.2c2c.anthk@openbsd.home.localhost>
 <cf8d7d8be71f91146788d056b1eb7eab@www.novabbs.com>
 <nnd$39d53bc1$68f61687@b5507bbc6e704cf6>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 15 May 2025 00:51:28 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="391209"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="XPw7UV90Iy7EOhY4YuUXhpdoEf5Vz7K+BsxA/Cx8bVc";
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <nnd$39d53bc1$68f61687@b5507bbc6e704cf6>
X-Spam-Checker-Version: SpamAssassin 4.0.0

On 14/05/2025 7:17 pm, 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").
> ...

Except eForth's FOR NEXT had AFT WHILE etc to effect such things.  Never say never?
I would say we "prefer to use" DO LOOP because when all said and done it hasn't been
bettered.  Immediate LEAVE ?DO UNLOOP full range loops were incremental improvements
that led to DO LOOP's ubiquitous status in Forth.  That said I can appreciate
restrictive environments where the decision was made to implement FOR NEXT instead.