diff --git a/basis/alien/libraries/finder/macosx/macosx.factor b/basis/alien/libraries/finder/macosx/macosx.factor index c6d260b6d9..867c5b1afb 100644 --- a/basis/alien/libraries/finder/macosx/macosx.factor +++ b/basis/alien/libraries/finder/macosx/macosx.factor @@ -121,7 +121,7 @@ PRIVATE> : framework-find ( name -- path ) dup dyld-find [ nip ] [ - ".framework" over start [ + ".framework" over subseq-start [ dupd head ] [ [ ".framework" append ] keep diff --git a/basis/game/input/iokit/iokit.factor b/basis/game/input/iokit/iokit.factor index 9eb30d7467..44518c6ad9 100644 --- a/basis/game/input/iokit/iokit.factor +++ b/basis/game/input/iokit/iokit.factor @@ -338,7 +338,7 @@ M: iokit-game-input-backend get-controllers ( -- sequence ) +controller-states+ get-global keys [ controller boa ] map ; : ?join ( pre post sep -- string ) - 2over start [ swap 2nip ] [ [ 2array ] dip join ] if ; + 2over subseq-start [ swap 2nip ] [ [ 2array ] dip join ] if ; M: iokit-game-input-backend product-string ( controller -- string ) handle>> diff --git a/basis/html/templates/fhtml/fhtml.factor b/basis/html/templates/fhtml/fhtml.factor index 1d72c04c43..2ec80f2983 100644 --- a/basis/html/templates/fhtml/fhtml.factor +++ b/basis/html/templates/fhtml/fhtml.factor @@ -25,7 +25,7 @@ M: template-lexer skip-word DEFER: <% delimiter : check-<% ( lexer -- col ) - "<%" swap [ line-text>> ] [ column>> ] bi start* ; + "<%" swap [ line-text>> ] [ column>> ] bi subseq-start-from ; : found-<% ( accum lexer col -- accum ) [ diff --git a/basis/interval-maps/interval-maps.factor b/basis/interval-maps/interval-maps.factor index a089fa3972..38c613b9c4 100644 --- a/basis/interval-maps/interval-maps.factor +++ b/basis/interval-maps/interval-maps.factor @@ -4,16 +4,13 @@ USING: accessors arrays assocs binary-search grouping kernel locals make math math.order sequences sequences.private sorting ; IN: interval-maps +! Intervals are triples of { start end value } TUPLE: interval-map { array array read-only } ; > [ start <=> ] with search nip ; inline + array>> [ first-unsafe <=> ] with search nip ; inline : interval-contains? ( key interval-node -- ? ) first2-unsafe between? ; inline @@ -22,7 +19,7 @@ ALIAS: value third-unsafe [ [ dup number? [ dup 2array ] when ] dip ] { } assoc-map-as ; : disjoint? ( node1 node2 -- ? ) - [ end ] [ start ] bi* < ; + [ second-unsafe ] [ first-unsafe ] bi* < ; : ensure-disjoint ( intervals -- intervals ) dup [ disjoint? ] monotonic? @@ -42,14 +39,14 @@ PRIVATE> check-interval-map [ drop ] [ find-interval ] 2bi [ nip ] [ interval-contains? ] 2bi - [ value t ] [ drop f f ] if ; inline + [ third-unsafe t ] [ drop f f ] if ; inline : interval-at ( key map -- value ) interval-at* drop ; inline : interval-key? ( key map -- ? ) interval-at* nip ; inline : interval-values ( map -- values ) - check-interval-map array>> [ value ] map ; + check-interval-map array>> [ third-unsafe ] map ; : ( specification -- map ) all-intervals [ first-unsafe second-unsafe ] sort-with diff --git a/basis/interval-sets/interval-sets.factor b/basis/interval-sets/interval-sets.factor index 6668a3c910..32b671d212 100644 --- a/basis/interval-sets/interval-sets.factor +++ b/basis/interval-sets/interval-sets.factor @@ -7,6 +7,7 @@ SPECIALIZED-ARRAY: uint IN: interval-sets ! Sets of positive integers +! Intervals are a pair of { start end } TUPLE: interval-set { array uint-array read-only } ; : spec>pairs ( sequence -- intervals ) [ dup number? [ dup 2array ] when ] map ; -ALIAS: start first-unsafe -ALIAS: end second-unsafe - : disjoint? ( node1 node2 -- ? ) - [ end ] [ start ] bi* < ; + [ second-unsafe ] [ first-unsafe ] bi* < ; : (delete-redundancies) ( seq -- ) dup length { diff --git a/basis/mime/multipart/multipart.factor b/basis/mime/multipart/multipart.factor index d8daba5be1..2072b7cbd4 100644 --- a/basis/mime/multipart/multipart.factor +++ b/basis/mime/multipart/multipart.factor @@ -46,7 +46,7 @@ C: mime-variable : dump-until-separator ( multipart -- multipart ) dup [ current-separator>> ] [ bytes>> ] bi - [ nip ] [ start ] 2bi [ + [ nip ] [ subseq-start ] 2bi [ cut-slice [ mime-write ] [ over current-separator>> length short tail-slice >>bytes ] bi* diff --git a/basis/multiline/multiline.factor b/basis/multiline/multiline.factor index 69389f68c2..ce5abbeac5 100644 --- a/basis/multiline/multiline.factor +++ b/basis/multiline/multiline.factor @@ -42,7 +42,7 @@ SYNTAX: STRING: :: (scan-multiline-string) ( i end lexer -- j ) lexer line-text>> :> text lexer still-parsing? [ - end text i start* [| j | + end text i subseq-start-from [| j | i j text subseq % j end length + ] [ text i short tail % CHAR: \n , diff --git a/basis/urls/urls.factor b/basis/urls/urls.factor index 93fea04e4d..d57a474769 100644 --- a/basis/urls/urls.factor +++ b/basis/urls/urls.factor @@ -141,7 +141,7 @@ PRIVATE> { [ dup "/" head? ] [ nip ] } { [ dup empty? ] [ drop ] } { [ over "/" tail? ] [ append ] } - { [ "/" pick start not ] [ nip ] } + { [ "/" pick subseq-start not ] [ nip ] } [ [ "/" split1-last drop "/" ] dip 3append ] } cond ; diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index adc7a750ca..8d70f695bf 100644 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -1146,11 +1146,11 @@ HELP: cut* { $values { "seq" sequence } { "n" "a non-negative integer" } { "before" sequence } { "after" sequence } } { $description "Outputs a pair of sequences, where " { $snippet "after" } " consists of the last " { $snippet "n" } " elements of " { $snippet "seq" } ", while " { $snippet "before" } " holds the remaining elements. Both output sequences have the same type as " { $snippet "seq" } "." } ; -HELP: start* +HELP: subseq-start-from { $values { "subseq" sequence } { "seq" sequence } { "n" "a start index" } { "i" "a start index" } } { $description "Outputs the start index of the first contiguous subsequence equal to " { $snippet "subseq" } ", starting the search from the " { $snippet "n" } "th element. If no matching subsequence is found, outputs " { $link f } "." } ; -HELP: start +HELP: subseq-start { $values { "subseq" sequence } { "seq" sequence } { "i" "a start index" } } { $description "Outputs the start index of the first contiguous subsequence equal to " { $snippet "subseq" } ", or " { $link f } " if no matching subsequence is found." } ; @@ -1859,7 +1859,7 @@ ARTICLE: "sequences-search" "Searching sequences" last-index-from } "Finding the start of a subsequence:" -{ $subsections start start* } +{ $subsections subseq-start subseq-start-from } "Finding the index of an element satisfying a predicate:" { $subsections find diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 055392e882..7ff518819e 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -972,20 +972,20 @@ PRIVATE> -: start* ( subseq seq n -- i ) +: subseq-start-from ( subseq seq n -- i ) pick length [ pick length swap - 1 + ] keep - [ (start) ] curry (find-integer) 2nip ; + [ (subseq-start-from) ] curry (find-integer) 2nip ; -: start ( subseq seq -- i ) 0 start* ; inline +: subseq-start ( subseq seq -- i ) 0 subseq-start-from ; inline -: subseq? ( subseq seq -- ? ) start >boolean ; +: subseq? ( subseq seq -- ? ) subseq-start >boolean ; : drop-prefix ( seq1 seq2 -- slice1 slice2 ) 2dup mismatch [ 2dup min-length ] unless* diff --git a/core/splitting/splitting.factor b/core/splitting/splitting.factor index 5a413b916e..841b0125b4 100644 --- a/core/splitting/splitting.factor +++ b/core/splitting/splitting.factor @@ -30,7 +30,7 @@ PRIVATE> : (split1) ( seq subseq snip-quot -- before after ) [ swap [ - [ drop length ] [ start dup ] 2bi + [ drop length ] [ subseq-start dup ] 2bi [ [ nip ] [ + ] 2bi t ] [ 2drop f f f ] if diff --git a/core/strings/strings-tests.factor b/core/strings/strings-tests.factor index ae3b874620..28feb10d15 100644 --- a/core/strings/strings-tests.factor +++ b/core/strings/strings-tests.factor @@ -12,14 +12,14 @@ vectors ; { "abc" } [ "ab" "c" append ] unit-test { "abc" } [ "a" "b" "c" 3append ] unit-test -{ 3 } [ "a" "hola" start ] unit-test -{ f } [ "x" "hola" start ] unit-test -{ 0 } [ "" "a" start ] unit-test -{ 0 } [ "" "" start ] unit-test -{ 0 } [ "hola" "hola" start ] unit-test -{ 1 } [ "ol" "hola" start ] unit-test -{ f } [ "amigo" "hola" start ] unit-test -{ f } [ "holaa" "hola" start ] unit-test +{ 3 } [ "a" "hola" subseq-start ] unit-test +{ f } [ "x" "hola" subseq-start ] unit-test +{ 0 } [ "" "a" subseq-start ] unit-test +{ 0 } [ "" "" subseq-start ] unit-test +{ 0 } [ "hola" "hola" subseq-start ] unit-test +{ 1 } [ "ol" "hola" subseq-start ] unit-test +{ f } [ "amigo" "hola" subseq-start ] unit-test +{ f } [ "holaa" "hola" subseq-start ] unit-test { "Beginning" } [ "Beginning and end" 9 head ] unit-test diff --git a/extra/combinators/extras/extras-tests.factor b/extra/combinators/extras/extras-tests.factor index 39a3504698..dc9e7fa7c5 100644 --- a/extra/combinators/extras/extras-tests.factor +++ b/extra/combinators/extras/extras-tests.factor @@ -41,23 +41,23 @@ IN: combinators.extras.tests { "hi " "there" } [ "hi there" { - { [ "there" over start ] [ cut ] } + { [ "there" over subseq-start ] [ cut ] } [ f ] } cond* ] unit-test { "hi " "there" } [ "hi there" { - { [ "foo" over start ] [ head f ] } - { [ "there" over start ] [ cut ] } + { [ "foo" over subseq-start ] [ head f ] } + { [ "there" over subseq-start ] [ cut ] } [ f ] } cond* ] unit-test { "hi there" f } [ "hi there" { - { [ "foo" over start ] [ head f ] } - { [ "bar" over start ] [ cut ] } + { [ "foo" over subseq-start ] [ head f ] } + { [ "bar" over subseq-start ] [ cut ] } [ f ] } cond* ] unit-test diff --git a/extra/io/encodings/detect/detect.factor b/extra/io/encodings/detect/detect.factor index ab6158b639..12da3efd97 100644 --- a/extra/io/encodings/detect/detect.factor +++ b/extra/io/encodings/detect/detect.factor @@ -17,7 +17,7 @@ default-8bit-encoding [ latin1 ] initialize : prolog-encoding ( string -- iana-encoding ) '[ - _ "encoding=" over start + _ "encoding=" over subseq-start 10 + swap [ [ 1 - ] dip nth ] [ index-from ] [ swapd subseq ] 2tri ] [ drop "UTF-8" ] recover ; diff --git a/extra/project-euler/047/047.factor b/extra/project-euler/047/047.factor index e7b585bf0d..91a1d3294c 100644 --- a/extra/project-euler/047/047.factor +++ b/extra/project-euler/047/047.factor @@ -80,7 +80,7 @@ SYMBOL: sieve ] each sieve get ; : consecutive-under ( m limit -- n/f ) - prime-tau-upto [ dup ] dip start ; + prime-tau-upto [ dup ] dip subseq-start ; PRIVATE> diff --git a/extra/rosetta-code/web-scraping/web-scraping.factor b/extra/rosetta-code/web-scraping/web-scraping.factor index 402a960124..c44ef62554 100644 --- a/extra/rosetta-code/web-scraping/web-scraping.factor +++ b/extra/rosetta-code/web-scraping/web-scraping.factor @@ -16,6 +16,6 @@ IN: rosetta-code.web-scraping : web-scraping-main ( -- ) "http://tycho.usno.navy.mil/cgi-bin/timer.pl" http-get nip - [ "UTC" swap start [ 9 - ] [ 1 - ] bi ] keep subseq print ; + [ "UTC" swap subseq-start [ 9 - ] [ 1 - ] bi ] keep subseq print ; MAIN: web-scraping-main diff --git a/extra/sequences/extras/extras.factor b/extra/sequences/extras/extras.factor index 5ae2255a80..4cb2536f7c 100644 --- a/extra/sequences/extras/extras.factor +++ b/extra/sequences/extras/extras.factor @@ -579,7 +579,7 @@ PRIVATE> :: (start-all) ( subseq seq increment -- indices ) 0 - [ [ subseq seq ] dip start* dup ] + [ [ subseq seq ] dip subseq-start-from dup ] [ [ increment + ] keep ] produce nip ; : start-all ( subseq seq -- indices ) diff --git a/misc/vim/syntax/factor.vim b/misc/vim/syntax/factor.vim index 1a8328fa48..6eb98a445b 100644 --- a/misc/vim/syntax/factor.vim +++ b/misc/vim/syntax/factor.vim @@ -57,7 +57,7 @@ syn keyword factorKeyword (clone) -rot 2bi 2bi* 2bi@ 2curry 2dip 2drop 2dup 2kee syn keyword factorKeyword 2cache >alist ?at ?of assoc assoc-all? assoc-any? assoc-clone-like assoc-combine assoc-diff assoc-diff! assoc-differ assoc-each assoc-empty? assoc-filter assoc-filter! assoc-filter-as assoc-find assoc-hashcode assoc-intersect assoc-like assoc-map assoc-map-as assoc-partition assoc-refine assoc-reject assoc-reject! assoc-reject-as assoc-size assoc-stack assoc-subset? assoc-union assoc-union! assoc= assoc>map assoc? at at* at+ cache change-at clear-assoc delete-at delete-at* enum enum? extract-keys harvest-keys harvest-values inc-at key? keys map>alist map>assoc maybe-set-at new-assoc of push-at rename-at set-at sift-keys sift-values substitute unzip value-at value-at* value? values zip zip-as zip-index zip-index-as syn keyword factorKeyword 2cleave 2cleave>quot 3cleave 3cleave>quot 4cleave 4cleave>quot alist>quot call-effect case case-find case>quot cleave cleave>quot cond cond>quot deep-spread>quot execute-effect linear-case-quot no-case no-case? no-cond no-cond? recursive-hashcode shallow-spread>quot spread to-fixed-point wrong-values wrong-values? syn keyword factorKeyword (all-integers?) (each-integer) (find-integer) * + - / /f /i /mod 2/ 2^ < <= > >= >bignum >fixnum >float >fraction >integer >rect ?1+ abs align all-integers? bignum bignum? bit? bitand bitnot bitor bits>double bits>float bitxor complex complex? denominator double>bits each-integer even? fast-gcd find-integer find-last-integer fixnum fixnum? float float>bits float? fp-bitwise= fp-infinity? fp-nan-payload fp-nan? fp-qnan? fp-sign fp-snan? fp-special? gcd if-zero imaginary-part integer integer>fixnum integer>fixnum-strict integer? log2 log2-expects-positive log2-expects-positive? mod neg neg? next-float next-power-of-2 number number= number? numerator odd? power-of-2? prev-float ratio ratio? rational rational? real real-part real? recip rect> rem sgn shift sq times u< u<= u> u>= unless-zero unordered? when-zero zero? -syn keyword factorKeyword 1sequence 2all? 2each 2each-from 2map 2map-as 2map-reduce 2reduce 2selector 2sequence 3append 3append-as 3each 3map 3map-as 3sequence 4sequence ?first ?last ?nth ?second ?set-nth accumulate accumulate! accumulate-as all? any? append append! append-as assert-sequence assert-sequence= assert-sequence? binary-reduce bounds-check bounds-check? bounds-error bounds-error? but-last but-last-slice cartesian-each cartesian-map cartesian-product change-nth check-slice clone-like collapse-slice collector collector-for concat concat-as copy count cut cut* cut-slice delete-all delete-slice drop-prefix each each-from each-index empty? exchange filter filter! filter-as find find-from find-index find-index-from find-last find-last-from first first2 first3 first4 flip follow fourth glue halves harvest head head* head-slice head-slice* head? if-empty immutable immutable-sequence immutable-sequence? immutable? index index-from indices infimum infimum-by insert-nth interleave iota iota-tuple iota-tuple? join join-as last last-index last-index-from length lengthen like longer longer? longest map map! map-as map-find map-find-last map-index map-index-as map-integers map-reduce map-sum max-length member-eq? member? midpoint@ min-length mismatch move new-like new-resizable new-sequence non-negative-integer-expected non-negative-integer-expected? nth nths pad-head pad-tail padding partition pop pop* prefix prepend prepend-as produce produce-as product push push-all push-either push-if reduce reduce-index reject reject! reject-as remove remove! remove-eq remove-eq! remove-nth remove-nth! repetition repetition? replace-slice replicate replicate-as rest rest-slice reverse reverse! reversed reversed? second selector selector-for sequence sequence-hashcode sequence= sequence? set-first set-fourth set-last set-length set-nth set-second set-third short shorten shorter shorter? shortest sift slice slice-error slice-error? slice? snip snip-slice start start* subseq subseq? suffix suffix! sum sum-lengths supremum supremum-by surround tail tail* tail-slice tail-slice* tail? third trim trim-head trim-head-slice trim-slice trim-tail trim-tail-slice unclip unclip-last unclip-last-slice unclip-slice unless-empty virtual-exemplar virtual-sequence virtual-sequence? virtual@ when-empty +syn keyword factorKeyword 1sequence 2all? 2each 2each-from 2map 2map-as 2map-reduce 2reduce 2selector 2sequence 3append 3append-as 3each 3map 3map-as 3sequence 4sequence ?first ?last ?nth ?second ?set-nth accumulate accumulate! accumulate-as all? any? append append! append-as assert-sequence assert-sequence= assert-sequence? binary-reduce bounds-check bounds-check? bounds-error bounds-error? but-last but-last-slice cartesian-each cartesian-map cartesian-product change-nth check-slice clone-like collapse-slice collector collector-for concat concat-as copy count cut cut* cut-slice delete-all delete-slice drop-prefix each each-from each-index empty? exchange filter filter! filter-as find find-from find-index find-index-from find-last find-last-from first first2 first3 first4 flip follow fourth glue halves harvest head head* head-slice head-slice* head? if-empty immutable immutable-sequence immutable-sequence? immutable? index index-from indices infimum infimum-by insert-nth interleave iota iota-tuple iota-tuple? join join-as last last-index last-index-from length lengthen like longer longer? longest map map! map-as map-find map-find-last map-index map-index-as map-integers map-reduce map-sum max-length member-eq? member? midpoint@ min-length mismatch move new-like new-resizable new-sequence non-negative-integer-expected non-negative-integer-expected? nth nths pad-head pad-tail padding partition pop pop* prefix prepend prepend-as produce produce-as product push push-all push-either push-if reduce reduce-index reject reject! reject-as remove remove! remove-eq remove-eq! remove-nth remove-nth! repetition repetition? replace-slice replicate replicate-as rest rest-slice reverse reverse! reversed reversed? second selector selector-for sequence sequence-hashcode sequence= sequence? set-first set-fourth set-last set-length set-nth set-second set-third short shorten shorter shorter? shortest sift slice slice-error slice-error? slice? snip snip-slice subseq-start subseq-start-from subseq subseq? suffix suffix! sum sum-lengths supremum supremum-by surround tail tail* tail-slice tail-slice* tail? third trim trim-head trim-head-slice trim-slice trim-tail trim-tail-slice unclip unclip-last unclip-last-slice unclip-slice unless-empty virtual-exemplar virtual-sequence virtual-sequence? virtual@ when-empty syn keyword factorKeyword +@ change change-global counter dec get get-global get-namestack global inc init-namespaces initialize namespace off on set set-global set-namestack toggle with-global with-scope with-variable with-variables syn keyword factorKeyword 1array 2array 3array 4array >array array array? pair pair? resize-array syn keyword factorKeyword (each-stream-block) (each-stream-block-slice) (stream-contents-by-block) (stream-contents-by-element) (stream-contents-by-length) (stream-contents-by-length-or-block) +byte+ +character+ bad-seek-type bad-seek-type? bl contents each-block each-block-size each-block-slice each-line each-morsel each-stream-block each-stream-block-slice each-stream-line error-stream flush input-stream input-stream? invalid-read-buffer invalid-read-buffer? lines nl output-stream output-stream? print read read-into read-partial read-partial-into read-until read1 readln seek-absolute seek-absolute? seek-end seek-end? seek-input seek-output seek-relative seek-relative? stream-bl stream-contents stream-contents* stream-copy stream-copy* stream-element-type stream-flush stream-length stream-lines stream-nl stream-print stream-read stream-read-into stream-read-partial stream-read-partial-into stream-read-partial-unsafe stream-read-unsafe stream-read-until stream-read1 stream-readln stream-seek stream-seekable? stream-tell stream-write stream-write1 tell-input tell-output with-error-stream with-error-stream* with-error>output with-input-output+error-streams with-input-output+error-streams* with-input-stream with-input-stream* with-output+error-stream with-output+error-stream* with-output-stream with-output-stream* with-output>error with-streams with-streams* write write1