In article <2024Jul12.100619@mips.complang.tuwien.ac.at>,   
   Anton Ertl wrote:   
   >Buzz McCool writes:   
   >>On 6/7/2024 1:32 PM, LIT wrote:   
   >>> : AVG DEPTH 0 SWAP DUP >R 0 DO SWAP + LOOP R> / . ;   
   >>   
   >>I coincidentally was doing averaging for the floating point stack when I   
   >>ran across this posting. Other than adding stack comments, how can I   
   >>improve this word?   
   >   
   >Eliminate DEPTH, e.g., by replacing it with a count of the elements   
   >you want to average over, or better, write a word that takes only a   
   >descriptor of, e.g., an array in memory, and averages over the array.   
   >   
   >Why should DEPTH not be used in this way? Because it means that AVG_   
   >consumes the whole stack and is useless in a word that keeps some   
   >temporary data deeper in the stack when it calls another word, an   
   >idiomatic way of using Forth.   
      
   The minimum you should do is storing FDEPTH at the return stack,   
   and then proceeding till you arrive at that stored depth.   
   >   
   >- anton   
      
   Groetjes Albert   
   --   
   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)   
|