firstn ( n -- quot ) - Factor Documentation

firstn ( n -- quot )
Generalized sequence words



Vocabulary
sequences .generalizations

Inputs
n an integer


Outputs
None

Word description
A generalization of first , first2 , first3 and first4 that pushes the first n elements of a sequence on the stack.

Examples
Some core words expressed in terms of firstn :
first 1 firstn
first2 2 firstn
first3 3 firstn
first4 4 firstn


Definition
USING: kernel math sequences ;

IN: sequences.generalizations

MACRO: firstn ( n -- quot )
[ [ drop ] ] [
[ 1 - ] keep [ [ swap bounds-check nip ] curry ] dip
[ firstn-unsafe ] curry compose
] if-zero ;

AltStyle によって変換されたページ (->オリジナル) /