USING: alien.libraries.finder sequences tools.test ;
-{ t } [ "m" find-library "libm.so" subsequence? ] unit-test
-{ t } [ "c" find-library "libc.so" subsequence? ] unit-test
+{ t } [ "m" find-library "libm.so" subseq-index? ] unit-test
+{ t } [ "c" find-library "libc.so" subseq-index? ] unit-test
[
" " split1 [ "()" in? ] trim "," split
[ [ unicode:blank? ] trim ] map
- [ ": Linux" subsequence? ] reject
+ [ ": Linux" subseq-index? ] reject
] dip 3array
] map ;
"ld" , "-t" , ":" split [ "-L" , , ] each
"-o" , "/dev/null" , "-l" name append ,
] { } make utf8 [ read-lines ] with-process-reader* 2drop
- "lib" name append '[ _ subsequence? ] find nip
+ "lib" name append '[ _ subseq-index? ] find nip
] [ f ] if* ;
PRIVATE>
} [ dyld-find ] map
] unit-test
-{ t } [ "m" find-library "libm.dylib" subsequence? ] unit-test
-{ t } [ "c" find-library "libc.dylib" subsequence? ] unit-test
-{ t } [ "bz2" find-library "libbz2.dylib" subsequence? ] unit-test
-{ t } [ "AGL" find-library "AGL.framework" subsequence? ] unit-test
+{ t } [ "m" find-library "libm.dylib" subseq-index? ] unit-test
+{ t } [ "c" find-library "libc.dylib" subseq-index? ] unit-test
+{ t } [ "bz2" find-library "libbz2.dylib" subseq-index? ] unit-test
+{ t } [ "AGL" find-library "AGL.framework" subseq-index? ] unit-test
: framework-find ( name -- path )
dup dyld-find [ nip ] [
- dup ".framework" subsequence-starts [
+ dup ".framework" subseq-index [
dupd head
] [
[ ".framework" append ] keep
USING: alien.libraries.finder sequences tools.test ;
-{ t } [ "kernel32" find-library "kernel32.dll" subsequence? ] unit-test
+{ t } [ "kernel32" find-library "kernel32.dll" subseq-index? ] unit-test
"." write flush
{
- member-eq? split harvest sift cut cut-slice subseq-start subsequence-starts
+ member-eq? split harvest sift cut cut-slice subseq-start subseq-index
index clone set-at reverse push-all class-of number>string string>number
like clone-like
} compile-unoptimized
:: longest-prefix ( ind seq -- start end )
ind dup ind + seq length min [a..b]
seq ind head-slice '[
- [ _ ] dip ind swap seq <slice> subsequence-starts
+ [ _ ] dip ind swap seq <slice> subseq-index
] map-find-last ;
:: create-pair ( ind seq -- array )
"sql-spec" get modifiers>> [ +not-null+ = ] none? ;
: delete-cascade? ( -- ? )
- "sql-spec" get modifiers>> { +on-delete+ +cascade+ } subsequence? ;
+ "sql-spec" get modifiers>> { +on-delete+ +cascade+ } subseq-index? ;
: sqlite-trigger, ( string -- )
{ } { } <simple-statement> 3, ;
ERROR: domain-name-contains-empty-label domain ;
: check-domain-name ( domain -- domain )
- dup ".." subsequence? [ domain-name-contains-empty-label ] when ;
+ dup ".." subseq-index? [ domain-name-contains-empty-label ] when ;
: >dotted ( domain -- domain' )
dup "." tail? [ "." append ] unless ;
{ "(all-integers?)" { "all-integers-from?" "0.99" } }
{ "short" { "bound" "0.99" } }
{ "map-integers" { "map-integers-as" "0.99" } }
- { "deep-subseq?" { "deep-subsequence?" "0.99" } }
+ { "deep-subseq?" { "deep-subseq-index?" "0.99" } }
}
: compute-assoc-fixups ( continuation name assoc -- seq )
+controller-states+ get-global keys [ controller boa ] map ;
: ?glue ( seq subseq sep -- string )
- 2over subsequence-starts [ drop nip ] [ glue ] if ;
+ 2over subseq-index [ drop nip ] [ glue ] if ;
M: iokit-game-input-backend product-string
handle>>
" white-space: pre-wrap; line-height: 125%;" append
] re-replace-with
- dup { "font-family: monospace;" "background-color:" } [ subsequence? ] with all? [
+ dup { "font-family: monospace;" "background-color:" } [ subseq-index? ] with all? [
" margin: 10px 0px;" append
] when
- dup { "border:" "background-color:" } [ subsequence? ] with all? [
+ dup { "border:" "background-color:" } [ subseq-index? ] with all? [
" border-radius: 5px;" append
] when ;
: fix-help-header ( classes -- classes )
dup [
- [ ".a" head? ] [ "#f4efd9;" subsequence? ] bi and
+ [ ".a" head? ] [ "#f4efd9;" subseq-index? ] bi and
] find [
"padding: 10px;" "padding: 0px;" replace
"background-color: #f4efd9;" "background-color: white;" replace
] re-replace-with
] map " " join "{ " " }" surround
] re-replace-with " " prepend
- dup "{ }" subsequence? [ drop f ] when
+ dup "{ }" subseq-index? [ drop f ] when
] map harvest append "}" suffix ;
: css-classes ( classes -- stylesheet )
] each classes sort-values css-classes body ;
: retina-image ( path -- path' )
- dup "@2x" subsequence? [ "." split1-last "@2x." glue ] unless ;
+ dup "@2x" subseq-index? [ "." split1-last "@2x." glue ] unless ;
: ?copy-file ( from to -- )
dup file-exists? [ 2drop ] [ copy-file ] if ;
simple-lint-error
] when
] [
- " " subsequence? [
+ " " subseq-index? [
"Paragraph text should not contain double spaces"
simple-lint-error
] when
first [
{ [ CHAR: space = ] [ CHAR: " = ] } 1||
] trim-head
- " " subsequence?
+ " " subseq-index?
] filter
[ drop ] [
swap <pathname> .
search-words [ { } ] [
[ all-articles ] dip
dup length 1 > [
- '[ article-words _ subsequence? ] filter
+ '[ article-words _ subseq-index? ] filter
] [
first '[ article-words [ _ head? ] any? ] filter
] if
DEFER: <% delimiter
: check-<% ( lexer -- col )
- [ column>> ] [ line-text>> ] bi "<%" subsequence-starts-from ;
+ [ column>> ] [ line-text>> ] bi "<%" subseq-index-from ;
: found-<% ( accum lexer col -- accum )
[
! hit the velox.ch website.
! { t } [
! "https://alice.sni.velox.ch" http-get nip
- ! [ "Great!" subsequence? ]
- ! [ "TLS SNI Test Site: alice.sni.velox.ch" subsequence? ] bi and
+ ! [ "Great!" subseq-index? ]
+ ! [ "TLS SNI Test Site: alice.sni.velox.ch" subseq-index? ] bi and
! ] unit-test
{ t } [
ERROR: mime-decoding-ran-out-of-bytes ;
: dump-until-separator ( multipart -- multipart )
- [ ] [ bytes>> ] [ current-separator>> ] tri
- over [ mime-decoding-ran-out-of-bytes ] unless
- 2dup subsequence-starts [
- swapd cut-slice
+ [ ] [ current-separator>> ] [ bytes>> ] tri
+ dup [ mime-decoding-ran-out-of-bytes ] unless
+ 2dup swap subseq-index [
+ cut-slice
[ mime-write ]
[ swap length tail-slice >>bytes ] bi*
] [
- swap
tuck [ length ] bi@ - 1 - cut-slice
[ mime-write ]
[ >>bytes ] bi* fill-bytes
'[ _ curry filter ] <smart-arrow> ; inline
: <string-search> ( values search quot -- model )
- '[ @ [ >case-fold ] bi@ subsequence? ] <search> ; inline
+ '[ @ [ >case-fold ] bi@ subseq-index? ] <search> ; inline
:: (scan-multiline-string) ( i end lexer -- j )
lexer line-text>> :> text
lexer still-parsing? [
- i text end subsequence-starts-from [| j |
+ i text end subseq-index-from [| j |
i j text subseq % j end length +
] [
text i bound tail % CHAR: \n ,
: message ( -- str )
55 [ "hello" ] replicate concat ;
-{ f } [ message >quoted "=\r\n" subsequence? ] unit-test
+{ f } [ message >quoted "=\r\n" subseq-index? ] unit-test
{ 1 } [ message >quoted split-lines length ] unit-test
-{ t } [ message >quoted-lines "=\r\n" subsequence? ] unit-test
+{ t } [ message >quoted-lines "=\r\n" subseq-index? ] unit-test
{ 4 } [ message >quoted-lines split-lines length ] unit-test
{ "===o" } [ message >quoted-lines split-lines [ last ] "" map-as ] unit-test
[ { { 1 2 3 } 4 } { { { 1 2 3 } 4 } 2 } deep-member? ] unit-test
{ f }
-[ { 1 2 3 { 4 } } { 1 2 3 4 } deep-subsequence? ] unit-test
+[ { 1 2 3 { 4 } } { 1 2 3 4 } deep-subseq-index? ] unit-test
{ t }
-[ { 1 2 3 4 } { 1 2 3 4 } deep-subsequence? ] unit-test
+[ { 1 2 3 4 } { 1 2 3 4 } deep-subseq-index? ] unit-test
{ t }
-[ { { 1 2 3 4 } } { 1 2 3 4 } deep-subsequence? ] unit-test
+[ { { 1 2 3 4 } } { 1 2 3 4 } deep-subseq-index? ] unit-test
{ 3 } [
{ 1 { 2 3 { 4 } } 5 { { 6 } 7 } } 0 [
_ swap dup branch? [ member? ] [ 2drop f ] if
] deep-find >boolean ;
-: deep-subsequence? ( seq subseq -- ? )
+: deep-subseq-index? ( seq subseq -- ? )
'[
- _ over branch? [ subsequence? ] [ 2drop f ] if
+ _ over branch? [ subseq-index? ] [ 2drop f ] if
] deep-find >boolean ;
: deep-map! ( ... obj quot: ( ... elt -- ... elt' ) -- ... obj )
! Just verifies that the presented output contains a callstack.
{ t } [
create-test-failure [ error. ] with-string-writer
- "OBJ-CURRENT-THREAD" subsequence?
+ "OBJ-CURRENT-THREAD" subseq-index?
] unit-test
<PRIVATE
MEMO: cached-image-path ( path -- image )
- [ load-image ] [ "@2x" subsequence? >>2x? ] bi ;
+ [ load-image ] [ "@2x" subseq-index? >>2x? ] bi ;
PRIVATE>
{ [ dup "/" head? ] [ nip ] }
{ [ dup empty? ] [ drop ] }
{ [ over "/" tail? ] [ append ] }
- { [ over "/" subsequence-starts not ] [ nip ] }
+ { [ over "/" subseq-index not ] [ nip ] }
[ [ "/" split1-last drop "/" ] dip 3append ]
} cond remove-dot-segments ;
{ $values { "i" "a start index" } { "seq" sequence } { "subseq" sequence } { "?" boolean } }
{ $description "Outputs " { $snippet "t" } " if the subseq starts at the " { $snippet "i" } "th element or outputs " { $link f } " if the sequence is not at that position." } ;
-HELP: subsequence-starts
+HELP: subseq-index
{ $values { "seq" sequence } { "subseq" sequence } { "i/f" "a start index or " { $snippet "f" } } }
{ $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: subsequence-starts-from
+HELP: subseq-index-from
{ $values { "n" "a start index" } { "seq" sequence } { "subseq" sequence } { "i/f" "a start index or " { $snippet "f" } } }
{ $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 } "." } ;
"Finding the start of a subsequence:"
{ $subsections
subseq-start
- subsequence-starts
- subsequence-starts-from
+ subseq-index
+ subseq-index-from
subseq-starts-at?
}
"Finding the index of an element satisfying a predicate:"
[ + _ nth-unsafe ] keep _ nth-unsafe =
] with all-integers? ; inline
-: subsequence-starts-from ( n seq subseq -- i/f )
+: subseq-index-from ( n seq subseq -- i/f )
[ [ length ] bi@ - 1 + ] 2keep
'[ _ _ subseq-starts-at? ] find-integer-from ; inline
-: subsequence-starts ( seq subseq -- i/f ) [ 0 ] 2dip subsequence-starts-from ; inline
+: subseq-index ( seq subseq -- i/f ) [ 0 ] 2dip subseq-index-from ; inline
-: subsequence? ( seq subseq -- ? ) subsequence-starts >boolean ; inline
+: subseq-index? ( seq subseq -- ? ) subseq-index >boolean ; inline
-: subseq-start ( subseq seq -- i/f ) swap subsequence-starts ; inline
+: subseq-start-from ( subseq seq n -- i/f )
+ spin subseq-index-from ; inline deprecated
-: subseq? ( subseq seq -- ? ) subseq-start >boolean ; inline
+: subseq-start ( subseq seq -- i/f ) swap subseq-index ; inline deprecated
+
+: subseq? ( subseq seq -- ? ) subseq-start >boolean ; inline deprecated
: drop-prefix ( seq1 seq2 -- slice1 slice2 )
2dup mismatch [ 2dup min-length ] unless*
<PRIVATE
: subseq-range ( seq subseq -- from/f to/f )
- [ subsequence-starts ] keep '[ dup _ length + ] [ f f ] if* ; inline
+ [ subseq-index ] keep '[ dup _ length + ] [ f f ] if* ; inline
: (split1) ( seq subseq snip-quot -- before after )
[ [ subseq-range ] keepd over ] dip [ 2nip f ] if ; inline
{ f } [ "amigo" "hola" subseq-start ] unit-test
{ f } [ "holaa" "hola" subseq-start ] unit-test
-{ 3 } [ "hola" "a" subsequence-starts ] unit-test
-{ f } [ "hola" "x" subsequence-starts ] unit-test
-{ 0 } [ "a" "" subsequence-starts ] unit-test
-{ 0 } [ "" "" subsequence-starts ] unit-test
-{ 0 } [ "hola" "hola" subsequence-starts ] unit-test
-{ 1 } [ "hola" "ol" subsequence-starts ] unit-test
-{ f } [ "hola" "amigo" subsequence-starts ] unit-test
-{ f } [ "hola" "holaa" subsequence-starts ] unit-test
+{ 3 } [ "hola" "a" subseq-index ] unit-test
+{ f } [ "hola" "x" subseq-index ] unit-test
+{ 0 } [ "a" "" subseq-index ] unit-test
+{ 0 } [ "" "" subseq-index ] unit-test
+{ 0 } [ "hola" "hola" subseq-index ] unit-test
+{ 1 } [ "hola" "ol" subseq-index ] unit-test
+{ f } [ "hola" "amigo" subseq-index ] unit-test
+{ f } [ "hola" "holaa" subseq-index ] unit-test
{ "Beginning" } [ "Beginning and end" 9 head ] unit-test
{ f } [ CHAR: I "team" member? ] unit-test
{ t } [ "ea" "team" subseq? ] unit-test
{ f } [ "actore" "Factor" subseq? ] unit-test
-{ t } [ "team" "ea" subsequence? ] unit-test
-{ f } [ "Factor" "actore" subsequence? ] unit-test
+{ t } [ "team" "ea" subseq-index? ] unit-test
+{ f } [ "Factor" "actore" subseq-index? ] unit-test
{ "end" } [ "Beginning and end" 14 tail ] unit-test
{ { t t t } } [
version-info
vm-version vm-compiler vm-compile-time 3array
- [ subsequence? ] with map
+ [ subseq-index? ] with map
] unit-test
dup "announce-list" of [ nip first random ] [ "announce" of ] if* ;
: scrape-url ( metainfo -- url/f )
- announce-url dup path>> "announce" subsequence? [
+ announce-url dup path>> "announce" subseq-index? [
[ "announce" "scrape" replace ] change-path
] [ drop f ] if ;
: directory-entries-without-git ( directory -- entries )
recursive-directory-entries
- [ name>> "/.git/" subsequence? ] reject ;
\ No newline at end of file
+ [ name>> "/.git/" subseq-index? ] reject ;
\ No newline at end of file
[ has-file-extension? ] filter ;
: without-git-paths ( paths -- paths' )
- [ "/.git/" subsequence? ] reject ;
+ [ "/.git/" subseq-index? ] reject ;
: without-node-modules-paths ( paths -- paths' )
- [ "/node_modules/" subsequence? ] reject ;
+ [ "/node_modules/" subseq-index? ] reject ;
: regular-directory-files ( path -- seq )
recursive-directory-files
{ "hi " "there" } [
"hi there" {
- { [ dup "there" subsequence-starts ] [ cut ] }
+ { [ dup "there" subseq-index ] [ cut ] }
[ f ]
} cond*
] unit-test
{ "hi " "there" } [
"hi there" {
- { [ dup "foo" subsequence-starts ] [ head f ] }
- { [ dup "there" subsequence-starts ] [ cut ] }
+ { [ dup "foo" subseq-index ] [ head f ] }
+ { [ dup "there" subseq-index ] [ cut ] }
[ f ]
} cond*
] unit-test
{ "hi there" f } [
"hi there" {
- { [ dup "foo" subsequence-starts ] [ head f ] }
- { [ dup "bar" subsequence-starts ] [ cut ] }
+ { [ dup "foo" subseq-index ] [ head f ] }
+ { [ dup "bar" subseq-index ] [ cut ] }
[ f ]
} cond*
] unit-test
: gemini-go ( args -- )
present [ DEFAULT-URL ] when-empty
- { [ dup "://" subsequence? ] [ "gemini://" head? ] } 1||
+ { [ dup "://" subseq-index? ] [ "gemini://" head? ] } 1||
[ "gemini://" prepend ] unless
dup "gemini://" head? [
[ add-history ] [ add-stack ] [ gemini-get ] tri
[ { [ name>> = ] [ closing?>> not ] } 1&& ] with find-all ;
: href-contains? ( str tag -- ? )
- "href" attribute* [ swap subsequence? ] [ 2drop f ] if ;
+ "href" attribute* [ swap subseq-index? ] [ 2drop f ] if ;
: find-hrefs ( vector -- vector' )
[ { [ name>> "a" = ] [ "href" attribute? ] } 1&& ] filter sift
: prolog-encoding ( string -- iana-encoding )
'[
- _ dup "encoding=" subsequence-starts
+ _ dup "encoding=" subseq-index
10 + swap [ [ 1 - ] dip nth ] [ index-from ] [ swapd subseq ] 2tri
] [ drop "UTF-8" ] recover ;
M: object lint ( obj -- seq ) drop f ;
M: callable lint ( quot -- seq )
- lint-definitions-keys get-global [ subsequence? ] with filter ;
+ lint-definitions-keys get-global [ subseq-index? ] with filter ;
M: word lint ( word -- seq/f )
def>> [ callable? ] deep-filter [ lint ] map concat ;
: git-pull-failed ( error -- )
dup output-process-error? [
- dup output>> "not uptodate. Cannot merge." subsequence?
+ dup output>> "not uptodate. Cannot merge." subseq-index?
[ git-repo-corrupted ]
[ rethrow ]
if
: nonce-already-used? ( assoc -- ? )
"error" of
[ "code" of "mwoauth-invalid-authorization" = ]
- [ "info" of "Nonce already used" subsequence-starts ] bi
+ [ "info" of "Nonce already used" subseq-index ] bi
and ;
: readonly? ( assoc -- ? )
] if ;
: parse-weather ( str -- str' )
- dup "VC" subsequence? [ "VC" "" replace t ] [ f ] if
+ dup "VC" subseq-index? [ "VC" "" replace t ] [ f ] if
[ (parse-weather) ]
[ [ " in the vicinity" append ] when ] bi* ;
ERROR: subseq-expected-but-got-eof n string expected ;
:: slice-til-string ( n string search -- n' string payload end-string )
- n string search subsequence-starts-from :> n'
+ n string search subseq-index-from :> n'
n' [ n string search subseq-expected-but-got-eof ] unless
n' search length + string
n n' string ?<slice>
] each sieve get ;
: consecutive-under ( limit m -- n/f )
- [ prime-tau-upto ] [ dup <repetition> ] bi* subsequence-starts ;
+ [ prime-tau-upto ] [ dup <repetition> ] bi* subseq-index ;
PRIVATE>
: first-subseq ( seq separators -- n separator )
tuck
- [ [ subsequence-starts ] dip 2array ] withd map-index sift-keys
+ [ [ subseq-index ] dip 2array ] withd map-index sift-keys
[ drop f f ] [ [ first ] infimum-by first2 rot nth ] if-empty ;
: multisplit ( string separators -- seq )
: <maxlicense> ( -- max ) -1 0 V{ } clone \ maxlicense boa ; inline
-: out? ( line -- ? ) "OUT" subsequence? ; inline
+: out? ( line -- ? ) "OUT" subseq-index? ; inline
: line-time ( line -- time ) split-words harvest fourth ; inline
: web-scraping-main ( -- )
"http://tycho.usno.navy.mil/cgi-bin/timer.pl" http-get nip
- [ "UTC" subsequence-starts [ 9 - ] [ 1 - ] bi ] keep subseq print ;
+ [ "UTC" subseq-index [ 9 - ] [ 1 - ] bi ] keep subseq print ;
MAIN: web-scraping-main
:: (start-all) ( seq subseq increment -- indices )
0
- [ seq subseq subsequence-starts-from dup ]
+ [ seq subseq subseq-index-from dup ]
[ [ increment + ] keep ] produce nip ;
: start-all ( seq subseq -- indices )
: name=value ( string -- remain term )
[ unicode:blank? ] trim
- dup ":`" subsequence? [ (name=value) ] [ f swap ] if ;
+ dup ":`" subseq-index? [ (name=value) ] [ f swap ] if ;
: name/values ( string -- remain terms )
[ dup { [ empty? not ] [ first CHAR: ` = not ] } 1&& ]
: zoneinfo-zones ( -- seq )
raw-zone-map keys
- [ "/" subsequence? ] partition
+ [ "/" subseq-index? ] partition
[ natural-sort ] bi@ append ;
GENERIC: zone-matches? ( string rule -- ? )
: comparison-day-string ( timestamp string -- timestamp )
{
- { [ dup ">=" subsequence? ] [ ">=" split1 swap [ string>number >>day ] dip day-abbrev>= ] }
- { [ dup "<=" subsequence? ] [ "<=" split1 swap [ string>number >>day ] dip day-abbrev<= ] }
+ { [ dup ">=" subseq-index? ] [ ">=" split1 swap [ string>number >>day ] dip day-abbrev>= ] }
+ { [ dup "<=" subseq-index? ] [ "<=" split1 swap [ string>number >>day ] dip day-abbrev<= ] }
[ string>number >>day ]
} cond ;