Re: Use of PICK and ROLL



duke wrote:
On Mar 13, 10:30 pm, "Ed" <nos...@xxxxxxxxxxx> wrote:
"duke" <dnorman...@xxxxxxxxxxxxxxxxxxxxx> wrote in messagenews:1173632732.451317.120600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hey....
First, thanks to all who replied concerning the appropriateness of
newbie questions on this newsgroup.
In Leo Wong's tutorial "Simple Forth" it states:
"Forth programmers generally don't use PICK and ROLL much, preferring
specific to general solutions, and avoiding the temptation to treat
the stack as array"
Other than suspecting that PICK and ROLL are not supported by every
"flavor" of Forth, I don't understand where the issue is. Could
someone please flesh out the above quotation for me, so that I can see
the issue? I *do not* question that there is an issue -- I simply
can't see it for looking. TIA...
PICK and ROLL are in the ANS CORE-EXT wordset and thus
virtually all forths of reasonable size support them.

Sadly PICK and ROLL have become Forth's "bogey men". It's
undeserved. Like any tool, it's a case of when and how it's used.
High usage of PICK or ROLL may indicate too many items on
the stack, in which case one should re-think the problem.
OTOH, one may encounter stack arguments/results that are lengthy
or complicated but cannot be changed e.g. a Windows API call.
In such cases PICK and ROLL can be useful in dealing with them.

Contrary to some claims, PICK as an operator is very efficient.

So for the benefit of this Forth newbie, would it be fair to summarize
the responses to this thread as follows:

1. Factor each "word" as much as possible within practical limits
2. use PICK very sparingly, and *only after* #1 has been achieved
3. Refrain from using ROLL as much as possible, *if ever*

Pretty close. PICK can be used sparingly, with low numbers (2, 3 maybe). Forget ROLL. In doing your factoring, look for components that (a) can be re-used; or (b) will make testing easier (e.g. insides of loops).

Cheers,
Elizabeth


--
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310-491-3356
5155 W. Rosecrans Ave. #1018 Fax: +1 310-978-9454
Hawthorne, CA 90250
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================
.



Relevant Pages

  • Re: Why does the Shuttle roll
    ... It doesn't roll exactly 180 degrees. ... onto its trajectory, the orbiter is "heads-down", under the stack. ...
    (sci.space.history)
  • Re: Use of PICK and ROLL
    ... An array, in contrast, may be accessed at any point: ... PICK and ROLL are therefore array operations, not stack ... I thuoght the point was that if you needed to change the search order ...
    (comp.lang.forth)
  • Re: Use of PICK and ROLL
    ... ROLL are touted as the best solution, ... As general advice, if you are tempted to use PICK and ROLL to solve a ... knotty stack problem, you are better advised to find out what caused ... As a general Forth technique, ...
    (comp.lang.forth)
  • Re: Use of PICK and ROLL
    ... An array, in contrast, may be accessed at any point: ... PICK and ROLL are therefore array operations, not stack ... I thuoght the point was that if you needed to change the search order ...
    (comp.lang.forth)
  • Re: Use of PICK and ROLL
    ... newbie questions on this newsgroup. ... "flavor" of Forth, I don't understand where the issue is. ... Sadly PICK and ROLL have become Forth's "bogey men". ... the stack, in which case one should re-think the problem. ...
    (comp.lang.forth)

Loading