Handbook
Glossary
pad-center ( seq n elt -- padded )
Vocabulary
sequences
.
extras
Inputs
seq
a
sequence
n
a non-negative integer
elt
an
object
Outputs
padded
a new sequence
Word description
Outputs a new sequence consisting of
seq
padded on the left and right with enough repetitions of
elt
to have the result be of length
n
.
Examples
USING: io sequences sequences.extras ; { "ab" "quux" } [ 5 CHAR: - pad-center print ] each
-ab-- quux-
Definition
USING:
kernel
math
math.order
sequences
;
IN:
sequences.extras
:
pad-center
( seq n elt -- padded )
swap
pick
length
[-]
[
drop
]
[
[
2/
]
[
over
-
]
bi
rot
[
<repetition>
]
curry
bi@
pick
surround-as
]
if-zero
;