Handbook
Glossary
firstn ( n -- quot )
Generalized sequence words
Prev:
nsequence ( n exemplar -- quot )
Next:
set-firstn ( n -- quot )
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
-
swap
bounds-check
2drop
]
[
firstn-unsafe
]
bi-curry
[
bi
]
2curry
]
if-zero
;