sequences.extras: Add a word to ensure that the underlying for slices is the same. Add a more forgiving version of merge-slices called span-slices.

locals-and-roots
Doug Coleman 2016-04-04 11:45:48 -07:00
parent 10cb7e12c1
commit 783cffe036
1 changed files with 10 additions and 0 deletions

View File

@ -198,6 +198,16 @@ ERROR: slices-don't-touch slice1 slice2 ;
: rotate ( seq n -- seq' )
over length mod dup 0 >= [ cut ] [ abs cut* ] if prepend ;
ERROR: underlying-mismatch slice1 slice2 ;
: ensure-same-underlying ( slice1 slice2 -- slice1 slice2 )
2dup [ seq>> ] bi@ eq? [ underlying-mismatch ] unless ;
: span-slices ( slice1 slice2 -- slice )
ensure-same-underlying
[ [ from>> ] bi@ min ]
[ [ to>> ] bi@ max ]
[ drop seq>> ] 2tri <slice> ;
:: rotate! ( seq n -- )
seq length :> len
n len mod dup 0 < [ len + ] when seq bounds-check drop 0 over