| Deutsch English Français Italiano |
|
<66e26787@news.ausics.net> View for Bookmarking (what is this?) Look up another Usenet article |
Date: Thu, 12 Sep 2024 14:01:10 +1000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!] Newsgroups: comp.lang.forth References: <nnd$61e0ad9a$48ed61c2@b4d945e456041481> <vasqjd$icjm$1@dont-email.me> <aea5eb9efcc8f053ce5dd7ff60e9b808@www.novabbs.com> <nnd$14b31e9e$1edc4d58@02f458c65ed0f6f1> Content-Language: en-GB From: dxf <dxforth@gmail.com> In-Reply-To: <nnd$14b31e9e$1edc4d58@02f458c65ed0f6f1> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NNTP-Posting-Host: news.ausics.net Message-ID: <66e26787@news.ausics.net> Organization: Ausics - https://newsgroups.ausics.net Lines: 25 X-Complaints: abuse@ausics.net Path: ...!weretis.net!feeder9.news.weretis.net!news.bbs.nz!news.ausics.net!not-for-mail Bytes: 1933 On 11/09/2024 7:20 pm, Hans Bezemer wrote: > On 30-08-2024 22:32, minforth wrote: >> Two classic answers: >> use DO..LOOPs to hide away loop indices >> use locals if you have too many parameters >> (some technical/physical formulas are difficult >> or impossible to factorise into smaller words >> which would otherwise be the classic Forth mantra) > > Tips: > - Use multiple Return Stack registers (R@, R'@, R"@); > - If parameters come in duplets or triplets, use corresponding stack operators (3DUP, 3OVER, 3DROP); > - Reorganize parameters at the *very start* of the program in a more palatable order. It saves stack juggling later on; > - Maybe a strange one, but codify stack patterns! > E.g. SPIN ( a b c -- c b a) > STOW ( a b -- a a b) > RISE ( a b c -- b a c) > > It helps you to THINK in these patterns and more easily recognize them. It depends highly on your coding habits, so it helps to analyze your legacy code to see if they often occur. swap rot 0 over swap 0 rot swap 1