Sujet : Re: Back & Forth - Co-routines
De : the.beez.speaks (at) *nospam* gmail.com (Hans Bezemer)
Groupes : comp.lang.forthDate : 31. Jan 2025, 16:25:58
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$7362f28c$5ccd981a@2cfb59244f115bf6>
References : 1 2
User-Agent : Mozilla Thunderbird
On 31-01-2025 08:33, dxf wrote:
On 31/01/2025 4:42 am, Hans Bezemer wrote:
The lot of you have contributed to this episode - by discussing the previous episode on local variables.
>
I thank you for your comments - and decided it was worth its own episode: https://youtu.be/FH4tWf9vPrA
>
More than worth! ;-)
Thanks Hans!
Not sure if previously mentioned but here's another version of LOCAL
: ;: >r ;
: LOCAL ( x adr -- )
r> -rot dup @ over 2>r ! ;: 2r> ! ;
variable A variable B 8 a ! 7 b !
: divide ( a b -- ) b local a local
a @ b @ / . cr ;
15 3 divide a ? b ?
I'm sure it works - but IMHO it heavily depends on whether those words are primitives or not. E.g. in 4tH this expends to:
: local r> rot rot dup @ over >r >r ! ;: r> r> ! ;
And if I want to be pedantic, I have to include two SWAPs as well for the proper definition of 2>R and 2R> - not to mention that you sometimes *DON'T* want to initialize your locals.
Another (consequential) disadvantage of this definition is that you have to *DEFINE* your words in reverse - a drawback which it shares with the original ANS LOCALS wordset.
Anyways, it may be useful to some people. Since I tend to use my LOCALs in conjunction with the 4tH preprocessor, I stick with the old version. It runs this one unmodified:
: LT1 {: a b | c -- f :}
CR ." Hello1 " CR a ;
T{ 3 4 LT1 => 3 }T \ Outputs Hello1
: LT2 {: a | b c e :}
CR ." Hello2 " CR ;
T{ 3 LT2 => }T \ Outputs Hello2
: LT3 {: a b c -- :}
CR ." Hello3 " CR ;
T{ 3 4 5 LT3 => }T \ Outputs Hello3
: LT4 {: a b c :}
CR ." Hello4 " CR ;
T{ 3 4 5 LT4 => }T \ Outputs Hello4
: LT5 {: a | b c d -- e f g :}
CR ." Hello5 " CR
a 2* to b b 2* to c c 2* to d
b c d ;
T{ 3 LT5 => 6 12 24 }T \ Outputs Hello5
But as usual - thanks to the feedback!
Hans Bezemer