]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: Add a word to ensure that the underlying for slices is the same...
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 4 Apr 2016 18:45:48 +0000 (11:45 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 4 Apr 2016 18:47:46 +0000 (11:47 -0700)
extra/sequences/extras/extras.factor

index 7c3caa7b4a91e44c6fd23e986b1922992e23944b..55f24785a1b37cd8aeb8ec7588c1e624d546e53c 100644 (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