0 swap [ append ] change-nth ;
: append-last ( str seq -- )
- [ length 1 - ] keep [ prepend ] change-nth ;
+ index-of-last [ prepend ] change-nth ;
: loc-col/str ( loc document -- str col )
[ first2 swap ] dip nth swap ;
[ space? ] trim ;
: unwrap ( str -- str' )
- 1 swap [ length 1 - ] keep subseq ;
+ 1 swap index-of-last subseq ;
: uncomment ( str -- str' )
";#" [ over index [ head ] when* ] each ;
[ length 2 - ] [ nth-unsafe ] bi ; inline
: pop-unsafe ( seq -- elt )
- [ length 1 - ] keep [ nth-unsafe ] [ shorten ] 2bi ; inline
+ index-of-last [ nth-unsafe ] [ shorten ] 2bi ; inline
: check-length ( seq n -- seq )
[ dup length ] [ >= ] bi* [ json-error ] unless ; inline
[ drop 1 + dup ] map! 2drop ; inline
: increment-last ( seq -- )
- [ [ length 1 - ] keep [ 1 + ] change-nth-unsafe ] unless-empty ; inline
+ [ index-of-last [ 1 + ] change-nth-unsafe ] unless-empty ; inline
:: next-combination ( seq n -- seq )
seq n find-max-index [
dup full? [ [ level>> 1node ] keep swap ] [ node-add f ] if ;
: new-last ( val seq -- seq' )
- [ length 1 - ] keep new-nth ;
+ index-of-last new-nth ;
: node-set-last ( child node -- node' )
clone [ new-last ] change-children ;
assoc-size 0 = ; inline
: assoc-stack ( key seq -- value )
- [ length 1 - ] keep assoc-stack-from ; flushable
+ index-of-last assoc-stack-from ; flushable
: assoc-subset? ( assoc1 assoc2 -- ? )
[ at* [ = ] [ 2drop f ] if ] with-assoc assoc-all? ;
[ path-separator? ] trim-head ;
: last-path-separator ( path -- n ? )
- [ length 1 - ] keep [ path-separator? ] find-last-from ;
+ index-of-last [ path-separator? ] find-last-from ;
HOOK: root-directory? io-backend ( path -- ? )
: ?first ( seq -- elt/f ) 0 swap ?nth ; inline
: ?second ( seq -- elt/f ) 1 swap ?nth ; inline
: ?last ( seq -- elt/f )
- [ length 1 - ] keep over 0 <
+ index-of-last over 0 <
[ 2drop f ] [ nth-unsafe ] if ; inline
MIXIN: virtual-sequence
: index-or-length ( seq n -- seq n' ) over length min ; inline
+: index-of-last ( seq -- n seq ) [ length 1 - ] keep ; inline
+
: head-slice ( seq n -- slice ) head-to-index <slice> ; inline
: tail-slice ( seq n -- slice ) index-to-tail <slice> ; inline
'[ _ find-last-from-unsafe ] bounds-check-find ; inline
: find-last ( ... seq quot: ( ... elt -- ... ? ) -- ... i elt )
- [ [ length 1 - ] keep ] dip find-last-from ; inline
+ [ index-of-last ] dip find-last-from ; inline
: find-index-from ( ... n seq quot: ( ... elt i -- ... ? ) -- ... i elt )
'[
: append! ( seq1 seq2 -- seq1 ) over push-all ; inline
: last ( seq -- elt )
- [ length 1 - ] keep
+ index-of-last
over 0 < [ bounds-error ] [ nth-unsafe ] if ; inline
<PRIVATE
PRIVATE>
: set-last ( elt seq -- )
- [ length 1 - ] keep
+ index-of-last
over 0 < [ bounds-error ] [ set-nth-unsafe ] if ; inline
: pop* ( seq -- ) [ length 1 - ] [ shorten ] bi ;
[ [ dup 1 + ] dip snip-slice ] keep append-as ;
: pop ( seq -- elt )
- [ length 1 - ] keep over 0 >=
+ index-of-last over 0 >=
[ [ nth-unsafe ] [ shorten ] 2bi ]
[ bounds-error ] if ;
: pop-start ( gb -- elem ) 0 swap pop-elem ;
-: pop-end ( gb -- elem ) [ length 1 - ] keep pop-elem ;
+: pop-end ( gb -- elem ) index-of-last pop-elem ;
: rotate-right ( gb -- )
dup [ pop-end ] keep push-start drop ;
] bounds-check-find ; inline
: find-last-index ( ... seq quot: ( ... elt i -- ... ? ) -- ... i elt )
- [ [ length 1 - ] keep ] dip find-last-index-from ; inline
+ [ index-of-last ] dip find-last-index-from ; inline
: map-find-last-index ( ... seq quot: ( ... elt index -- ... result/f ) -- ... result i elt )
[ find-last-index ] (map-find-index) ; inline
! Compute the starting index
/ truncate dupd *
! Compute the ending index
- swap over +
+ tuck +
! Take a slice
rot <slice> ;