update the article on shuffle words to hide away the more troublesome ones

db4
Joe Groff 2009-10-29 11:36:06 -05:00
parent 2599993093
commit f21ba7a759
1 changed files with 23 additions and 11 deletions

View File

@ -821,10 +821,26 @@ HELP: assert=
{ $values { "a" object } { "b" object } } { $values { "a" object } { "b" object } }
{ $description "Throws an " { $link assert } " error if " { $snippet "a" } " does not equal " { $snippet "b" } "." } ; { $description "Throws an " { $link assert } " error if " { $snippet "a" } " does not equal " { $snippet "b" } "." } ;
ARTICLE: "shuffle-words" "Shuffle words" ARTICLE: "shuffle-words-complex" "Complex shuffle words"
"Shuffle words rearrange items at the top of the data stack. They control the flow of data between words that perform actions." "These shuffle words tend to make code difficult to read and reason about. Code that uses them should almost always be rewritten in terms of the " { $link "dataflow-combinators" } "."
$nl $nl
"The " { $link "cleave-combinators" } ", " { $link "spread-combinators" } " and " { $link "apply-combinators" } " are closely related to shuffle words and should be used instead where possible because they can result in clearer code; also, see the advice in " { $link "cookbook-philosophy" } "." "Duplicating stack elements deep in the stack:"
{ $subsections
dupd
tuck
}
"Permuting stack elements deep in the stack:"
{ $subsections
swapd
rot
-rot
spin
roll
-roll
} ;
ARTICLE: "shuffle-words" "Shuffle words"
"Shuffle words rearrange items at the top of the data stack. They provide simple data flow control between words. More complex data flow control is available through the " { $link "dataflow-combinators" } "."
$nl $nl
"Removing stack elements:" "Removing stack elements:"
{ $subsections { $subsections
@ -839,21 +855,17 @@ $nl
dup dup
2dup 2dup
3dup 3dup
dupd
over over
2over 2over
pick pick
tuck
} }
"Permuting stack elements:" "Permuting stack elements:"
{ $subsections { $subsections
swap swap
swapd }
rot "There are additional, more complex stack shuffling words whose use is not recommended."
-rot { $subsections
spin "shuffle-words-complex"
roll
-roll
} ; } ;
ARTICLE: "equality" "Equality" ARTICLE: "equality" "Equality"