Deutsch   English   Français   Italiano  
<nnd$13102470$43ae45e7@43020320c3a269db>

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

Date: Thu, 15 May 2025 13:14:42 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Average of a [stack]
Newsgroups: comp.lang.forth
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>
 <048828e75f8e839eb96b9334b2604c0cda8e8d8a@i2pn2.org>
Content-Language: en-US
From: Hans Bezemer <the.beez.speaks@gmail.com>
In-Reply-To: <048828e75f8e839eb96b9334b2604c0cda8e8d8a@i2pn2.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$13102470$43ae45e7@43020320c3a269db>
Organization: KPN B.V.
Path: ...!news.roellig-ltd.de!open-news-network.org!weretis.net!feeder8.news.weretis.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feed.abavia.com!abe006.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 78
Injection-Date: Thu, 15 May 2025 13:14:42 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
Bytes: 4992

On 15-05-2025 02:51, dxf wrote:
> 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.
> 

BTW, in his "rationale" (which isn't exactly a rationale, because the 
foundations of his basic design choices are completely missing) the 
author of this abomination litters his epistle with sentences like:

"It's not the most readable control structure (..)"
"(..) even if the code is difficult to understand at first."
"Alternatively, (..), the DO .. LEAVE .. LOOP/+LOOP structure can be 
used for improving readability." *(SIC!)*

Which does not exactly raises confidence in the validity of his choices 
IMHO.

Hans Bezemer