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,710 of 117,927   
   Hans Bezemer to Hans Bezemer   
   Re: Avoid treating the stack as an array   
   05 Sep 24 17:37:03   
   
   From: the.beez.speaks@gmail.com   
      
   On 05-09-2024 17:18, Hans Bezemer wrote:   
   > On 31-08-2024 07:59, BuzzMcCool wrote:   
   >> On 8/30/24 18:05, dxf wrote:   
   >>> On 31/08/2024 2:04 am, Buzz McCool wrote:   
   >>>> ...   
   >>>> Does anyone have suggestions on a better approach when you have   
   >>>> several parameters and loop counts to deal with?   
   >>>   
   >>> I see little wrong with your example other than cosmetics - excess   
   >>> comments   
   >>> that don't add value and missing stack parameter comment in colon   
   >>> definitions.   
   >>>   
   >>   
   >> Thanks for the feedback. Yes I do need to work on my stack parameter   
   >> comments.   
   > Given that the area of the circle doesn't change - why recalculate that   
   > every time? Ok, I changed VolOfCirc a bit, but it saves me both time and   
   > complexity. Note this only works if there is a separate FP stack. Which   
   > is the standard nowadays.   
   >   
   > Alternatives:   
   > 1. Change the order of parameters (float last);   
   > 2. Change the order of parameters (carnal knowledge of the size of a   
   > float);   
   > 3. Specify the radius as an integer.   
      
   This is the same routine with a shared stack. Note I used option 3. here   
   - it retains the same possibilities as the original. Note this is in   
   4tH. F% is followed by an FP number:   
      
   include lib/fp2.4th   
   include lib/zenconst.4th   
   include 4pp/lib/float.4pp   
      
   : AreaOfCir fdup pi f* f* ;   
   aka f* VolOfCyl              ( 4tH alias)   
      
   : CylVolLoop                 ( radius start end --)   
      >r >r cr ." Radius " fdup fe.   
      AreaOfCir r> r> 1+ swap ?do   
        i s>f fdup cr ." Height " fe.   
        fover VolOfCyl ." Volume " fe.   
      loop fdrop cr   
      
      
   f% 1.2 1 20 CylVolLoop   
      
   Radius 1.E0   
   Height 1.E0 Volume 3.141592653589793238E0   
   Height 2.E0 Volume 6.283185307179586476E0   
   Height 3.E0 Volume 9.42477796076937971E0   
   ...   
   Height 19.E0 Volume 59.69026041820607152E0   
   Height 20.E0 Volume 62.83185307179586476E0   
      
   --- 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