Deutsch   English   Français   Italiano  
<775ad5020b3de3cc091ce71506dd0ac5fac16523@i2pn2.org>

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

Path: ...!weretis.net!feeder9.news.weretis.net!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: dxf <dxforth@gmail.com>
Newsgroups: comp.lang.forth
Subject: Re: "Back & Forth" - Local variables
Date: Tue, 11 Mar 2025 11:02:23 +1100
Organization: i2pn2 (i2pn.org)
Message-ID: <775ad5020b3de3cc091ce71506dd0ac5fac16523@i2pn2.org>
References: <nnd$75b7a2a4$616fdd6b@4f60b314ce95c9b9>
 <nnd$0a3352ed$2c40f494@296559c013ec38eb>
 <nnd$032b844d$734ee136@776df242e330d1d2>
 <nnd$18b00be1$6a41106c@750f2b64d19dca67>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 11 Mar 2025 00:02:23 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="3798669"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="XPw7UV90Iy7EOhY4YuUXhpdoEf5Vz7K+BsxA/Cx8bVc";
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <nnd$18b00be1$6a41106c@750f2b64d19dca67>
Bytes: 3601
Lines: 81

On 9/01/2025 6:13 am, albert@spenarnc.xs4all.nl wrote:
> In article <nnd$032b844d$734ee136@776df242e330d1d2>,
> Hans Bezemer  <the.beez.speaks@gmail.com> wrote:
>> On 08-01-2025 17:27, albert@spenarnc.xs4all.nl wrote:
>>
>>> I was impressed with the Behringer solution.
>>> (I didn't care about the politically correct solution.)
>>>
>>> ====================================
>>> : local{ R> SWAP DUP >R @ >R >R ;
>>> : }global R> R> R> ! >R ;
>>> =================
>>>
>>> But I can do you one better.
>>> Remember the word ;: from colorforth. That is actually a coroutine call.
>>> I call it CO. (Present in ciforth since the year 00)
>>
>> <snipped>
>>
>>>
>>> With CO the example become
>>> ---------------------------------------
>>> : LOCAL   R> SWAP DUP >R @ >R >R   CO   R> R> ! ;
>>>
>>> VARIABLE A
>>> VARIABLE B
>>>
>>> : divide
>>>     A LOCAL
>>>     B LOCAL
>>>     B ! A !  A @ B @ /
>>>     . CR
>>> ;
>>>
>>> 15 3 divide
>>> ---------------------------------------
>>>
>>> This saves a definition and a word-of-code, and a line for every
>>> LOCAL used. Now that is closer to what Chuck Moore would have used.
>>> Remember for Moore CO aka ;: is a standard word.
>>>
>>> CO is not standard but it should be, and it is elementary as hell.
>>
>> Couldn't find the source for either CO or ;: but I got some primitive,
>> high level form of co-routine in 4tH:
>>
>> ====================================
>> : yield r> r> swap >r >r ;             \ remember that ; compiles EXIT!
>> aka rdrop grab                         \ so add a [FORCE] when needed.
>> ====================================
> 
> That is the equivalent in high level code.
> 
> In assembler, assuming ESI is the interpreter pointer and EBP is the return
> stack pointer:
> 
> CODE CO
>             XCHG    ESI,[EBP]
>             NEXT,
> END-CODE
> 
> In assembler the return stack is uncluttered.
> ...

Just to clarify CO (coroutines) and

: ;:  >r ;

are different albeit related beasts.  So which one is Moore's?

BTW the latter is equivalent to the 'docol' run-time in most DTC forth.
In my case I'd just need to give the code fragment a name.  But is this
latter ;: worth it?  Its use seems to be restricted to restoring state
when a word completes.  It's not a "coroutine.

>>
>> Can't say how they measure up. But I guess co-routines is something
>> Chuck would like - since it's something you can implement quite easily.
>> So yes, I agree Chuck wouldn't waste that line ;-)
>>
>> Hans Bezemer