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 116,633 of 117,927   
   albert@spenarnc.xs4all.nl to Anton Ertl   
   Re: recursion (was: exercise in double n   
   15 Jul 24 20:16:11   
   
   In article <2024Jul15.152917@mips.complang.tuwien.ac.at>,   
   Anton Ertl  wrote:   
      
   >Gforth (development) also has FORWARD, which also allows you to do   
   >mutual recursion, e.g.   
   >   
   >forward foo   
   >   
   >: bar ( n -- ) dup . 1- foo ;   
   >   
   >: foo ( n -- ) dup 0> if bar else drop then ;   
   >   
   >5 foo \ prints "5 4 3 2 1 "   
   >   
   >let's see what the decompiler says:   
   >   
      
   >   
   >The definition of FORWARD is quite intricate and uses several recent   
   >features of Gforth.  Read all about it in   
   ><2018Dec31.161743@mips.complang.tuwien.ac.at>.   
      
   In a simple Forth like ciforth this is much easier:   
      
   \ Could use plain : , :F marks the definition as forward.   
   ': ALIAS :F   
   \ Resolve an earlier dummy definition for recursion.   
   : :R   >IN @ NAME FOUND >R >IN !   :   LATEST >DFA @ R> >DFA ! ;   
      
   We look up the previous definition and store it in the return stack.   
   After compilation, the data-field-address (pointing to high   
   level interpreted code) of the latest definition is copied to   
   the data-field-address of the forward definition header (dea).   
      
   [ NAME FOUND is approximately WORD FIND . ]   
      
      
   >- anton   
   --   
   Don't praise the day before the evening. One swallow doesn't make spring.   
   You must not say "hey" before you have crossed the bridge. Don't sell the   
   hide of the bear until you shot it. Better one bird in the hand than ten in   
   the air. First gain is a cat purring.            - the Wise from Antrim -   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

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


(c) 1994,  bbs@darkrealms.ca