home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,032 of 117,927   
   Hans Bezemer to dxf   
   Re: Back & Forth - Co-routines   
   31 Jan 25 16:25:58   
   
   From: the.beez.speaks@gmail.com   
      
   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   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca