Re: "Back & Forth" - Local variables

Liste des GroupesRevenir à cl forth 
Sujet : Re: "Back & Forth" - Local variables
De : albert (at) *nospam* spenarnc.xs4all.nl
Groupes : comp.lang.forth
Date : 08. Jan 2025, 17:27:45
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$0a3352ed$2c40f494@296559c013ec38eb>
References : 1
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <nnd$75b7a2a4$616fdd6b@4f60b314ce95c9b9>,
Hans Bezemer  <the.beez.speaks@gmail.com> wrote:
This is gonna get me lose a lot of subscribers, but it has been a hot
topic on YT. So I had to address it sooner or later.
>
Still, there is a little known implementation of Locals that looks like
Chuck Moore could have invented it - if he had wanted to.
>
Anyways, I expanded it into a fully Forth 2012 compliant 4tH
implementation, which essentially means you can now port your locals
infested programs to 4tH without ever changing a line.
>
I hope you are happy now :)
>
https://www.youtube.com/watch?v=Y7cax2fDS84

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)

An example of its use is the following:
:NONAME .S ;  ' LIST decorated
decorated is not the point. The noname decorates LIST with
the anonymous function, so that the stack is printed, before LIST.
Now we go one step further:
:NONAME .S CO ." AFTER " .S ;  ' LIST decorated
The noname decorates LIST with the anonymous function, so that the
stack is printed, before, but now noname is suspended, LIST is
executed as a coroutine, and afterword the stack is printed once more.

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.

******************************************************
*    The code for CO is one third of the code of R>. *
******************************************************
Look for yourself e.g. https://github.com/albertvanderhorst/ciforth

>
Hans Bezemer

Groetjes Albert

P.S. This doesn't convince me to use local values.
--
Temu exploits Christians: (Disclaimer, only 10 apostles)
Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
And Gifts For Friends Family And Colleagues.

Date Sujet#  Auteur
8 Jan 25 * "Back & Forth" - Local variables39Hans Bezemer
8 Jan 25 +- Re: "Back & Forth" - Local variables1dxf
8 Jan 25 `* Re: "Back & Forth" - Local variables37albert
8 Jan 25  +* Re: "Back & Forth" - Local variables21Hans Bezemer
8 Jan 25  i`* Re: "Back & Forth" - Local variables20albert
8 Jan 25  i +* Re: "Back & Forth" - Local variables2mhx
9 Jan 25  i i`- Re: "Back & Forth" - Local variables1albert
11 Mar 25  i `* Re: "Back & Forth" - Local variables17dxf
11 Mar 25  i  +- Re: "Back & Forth" - Local variables1dxf
11 Mar 25  i  +* Re: "Back & Forth" - Local variables4Hans Bezemer
12 Mar 25  i  i`* Re: "Back & Forth" - Local variables3dxf
12 Mar 25  i  i +- Re: "Back & Forth" - Local variables1albert
13 Mar 25  i  i `- Re: "Back & Forth" - Local variables1dxf
12 Mar 25  i  `* Re: "Back & Forth" - Local variables11dxf
13 Mar 25  i   `* Re: "Back & Forth" - Local variables10sjack
14 Mar 25  i    `* Re: "Back & Forth" - Local variables9dxf
14 Mar 25  i     +* Re: "Back & Forth" - Local variables2sjack
14 Mar 25  i     i`- Re: "Back & Forth" - Local variables1sjack
16 Mar 25  i     `* Re: "Back & Forth" - Local variables6Hans Bezemer
16 Mar 25  i      `* Re: "Back & Forth" - Local variables5sjack
16 Mar 25  i       +- Re: "Back & Forth" - Local variables1sjack
17 Mar 25  i       +- Re: "Back & Forth" - Local variables1sjack
17 Mar 25  i       `* Re: "Back & Forth" - Local variables2sjack
18 Mar 25  i        `- Re: "Back & Forth" - Local variables1dxf
8 Jan 25  +* Re: "Back & Forth" - Local variables13Hans Bezemer
8 Jan 25  i`* Re: "Back & Forth" - Local variables12dxf
9 Jan 25  i `* Re: "Back & Forth" - Local variables11dxf
9 Jan 25  i  +* Re: "Back & Forth" - Local variables9albert
9 Jan 25  i  i+* Re: "Back & Forth" - Local variables7dxf
9 Jan 25  i  ii`* Re: "Back & Forth" - Local variables6Hans Bezemer
10 Jan 25  i  ii +* Re: "Back & Forth" - Local variables4dxf
10 Jan 25  i  ii i+- Re: "Back & Forth" - Local variables1Hans Bezemer
10 Jan 25  i  ii i`* Re: "Back & Forth" - Local variables2sjack
10 Jan 25  i  ii i `- Re: "Back & Forth" - Local variables1dxf
10 Jan 25  i  ii `- Re: "Back & Forth" - Local variables1albert
9 Jan 25  i  i`- xts and return addresses (was: "Back & Forth" - Local variables)1Anton Ertl
9 Jan 25  i  `- Re: "Back & Forth" - Local variables1sjack
10 Jan 25  `* Re: "Back & Forth" - Local variables2albert
10 Jan 25   `- Re: "Back & Forth" - Local variables1Hans Bezemer

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal