Deutsch English Français Italiano |
<vasqjd$icjm$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Buzz McCool <buzz_mccool@yahoo.com> Newsgroups: comp.lang.forth Subject: Avoid treating the stack as an array [Re: "Back & Forth" is back!] Date: Fri, 30 Aug 2024 09:04:58 -0700 Organization: A noiseless patient Spider Lines: 66 Message-ID: <vasqjd$icjm$1@dont-email.me> References: <nnd$61e0ad9a$48ed61c2@b4d945e456041481> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 30 Aug 2024 18:05:01 +0200 (CEST) Injection-Info: dont-email.me; posting-host="05328e46e491c7ebcfff0dd7a0bfbb25"; logging-data="602742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FiukHbKIhv0BIS0jg+Y2TrnqWpvA9Zs8=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:xT68827X+a3wV3vKncgaKbU836U= In-Reply-To: <nnd$61e0ad9a$48ed61c2@b4d945e456041481> Content-Language: en-US Bytes: 3606 On 8/10/2024 3:57 AM, Hans Bezemer wrote: > After explaining why Forth is so hard, I'm explaining what reasons there > could be to use it. With a little personal journey put in as a side note. > > https://www.youtube.com/watch?v=MXKZPGzlx14 I looked through a few of these videos and found them interesting, thank you Hans for going to the trouble of making them. I found Hans' recommendation on one of the videos (if I'm paraphrasing it correctly) to avoid using the stack for more than two or three values as treating the stack as an array makes for incomprehensible code, enlightening. I am trying to follow this recommendation, but am running into trouble when trying to pass parameters into a loop. I'm trying to avoid using the stack as a large array but what I came up by injecting a parameter with a variable doesn't seem right. Does anyone have suggestions on a better approach when you have several parameters and loop counts to deal with? (Trivial Example) : AreaOfCir 2.0e f** pi f* ; \ w/ radius on stack, \ compute area (radius^2 * pi) : VolOfCyl AreaOfCir f* ; \ w/ height & radius on stack, \ compute vol (height * area) 1.0e AreaOfCir fe. 3.1416E0 2.0e 1.0e VolOfCyl fe. 6.2832E0 fvariable radius \ create a floating point variable 1.0e radius f! \ store 1.0 into radius radius f@ fe. \ fetch and print radius 1.0000E0 : CylVolLoop cr ." Radius " radius f@ fe. \ print a new line and then fetch and print radius 1 \ start counter from a cyl height of 1 begin dup 20 <= \ duplicate counter to see if counter <= end value while \ while true (i.e. counter is <= to 20) dup \ duplicate counter s>f \ convert counter (height) to floating point fdup \ duplicate height to print and use to compute vol cr ." Height " fe. \ print a new line and then print height radius f@ \ fetch radius VolOfCyl \ compute volume .." Volume " fe. \ print volume 1 + \ add one to counter repeat \ repeat the test at the "begin" word drop ; \ remove the leftover loop counter value CylVolLoop \ Execute CylVolLoop word Radius 1.0000E0 Height 1.0000E0 Volume 3.1416E0 Height 2.0000E0 Volume 6.2832E0 .... Height 19.000E0 Volume 59.690E0 Height 20.000E0 Volume 62.832E0