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,005 of 117,927   
   albert@spenarnc.xs4all.nl to the.beez.speaks@gmail.com   
   Re: "Back & Forth" - Local variables   
   08 Jan 25 20:13:23   
   
   In article ,   
   Hans Bezemer   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)   
   >   
   >   
   >   
   >>   
   >> 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.   
      
   >   
   >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   
   --   
   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.   
      
   --- 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