limit: func [
"Make sure val falls between lower and upper bounds, inclusive; uses length for series values."
val
lower [integer!]
upper [integer!]
/show "For series values, show extension/truncation (dot/none for extension, 3 dots for truncation)."
/local fill
][
either not series? val [max min val upper lower] [
either all [
upper >= length? val
lower <= length? val
] [val] [
; If extending the series, use NONE as the fill value, so the
; block can still be processed easily.
fill: either any-string? val ["."] [none]
head either lower >= length? val [
insert/only/dup tail val fill subtract lower length? val
][
clear skip val upper
either show [change/dup skip tail val -3 '. 3] [val]
]
]
]
]