ndup ( n -- )

Factor handbook » The language » Combinators » Generalized shuffle words and combinators » Generalized shuffle words

Factor handbook » The language » Combinators » Generalized shuffle words and combinators » Generalized shuffle words

Next: | dupn ( n -- quot ) |

Vocabulary

generalizations

Inputs

Outputs

None

Word description

A generalization of dup, 2dup and 3dup that can work for any number of items. The n topmost items on the stack will be copied and placed on the top of the stack.

Examples

Some core words expressed in terms of ndup:

Definition

generalizations

Inputs

n | an integer |

Outputs

None

Word description

A generalization of dup, 2dup and 3dup that can work for any number of items. The n topmost items on the stack will be copied and placed on the top of the stack.

Examples

USING: prettyprint generalizations kernel
sequences.generalizations ;
1 2 3 4 4 ndup 8 narray .

{ 1 2 3 4 1 2 3 4 }

{ 1 2 3 4 1 2 3 4 }

Some core words expressed in terms of ndup:

dup | 1 ndup |

2dup | 2 ndup |

3dup | 3 ndup |

Definition