USING: alien.libraries.finder sequences tools.test ;
-{ t } [ "libm.so" "m" find-library subseq? ] unit-test
-{ t } [ "libc.so" "c" find-library subseq? ] unit-test
+{ t } [ "m" find-library "libm.so" find-subseq? ] unit-test
+{ t } [ "c" find-library "libc.so" find-subseq? ] unit-test
[
" " split1 [ "()" in? ] trim "," split
[ [ unicode:blank? ] trim ] map
- [ ": Linux" swap subseq? ] reject
+ [ ": Linux" find-subseq? ] 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 '[ _ swap subseq? ] find nip
+ "lib" name append '[ _ find-subseq? ] find nip
] [ f ] if* ;
PRIVATE>
} [ dyld-find ] map
] unit-test
-{ t } [ "libm.dylib" "m" find-library subseq? ] unit-test
-{ t } [ "libc.dylib" "c" find-library subseq? ] unit-test
-{ t } [ "libbz2.dylib" "bz2" find-library subseq? ] unit-test
-{ t } [ "AGL.framework" "AGL" find-library subseq? ] unit-test
+{ t } [ "m" find-library "libm.dylib" find-subseq? ] unit-test
+{ t } [ "c" find-library "libc.dylib" find-subseq? ] unit-test
+{ t } [ "bz2" find-library "libbz2.dylib" find-subseq? ] unit-test
+{ t } [ "AGL" find-library "AGL.framework" find-subseq? ] unit-test
: framework-find ( name -- path )
dup dyld-find [ nip ] [
- ".framework" over subseq-start [
+ dup ".framework" find-subseq [
dupd head
] [
[ ".framework" append ] keep
USING: alien.libraries.finder sequences tools.test ;
-{ t } [ "kernel32.dll" "kernel32" find-library subseq? ] unit-test
+{ t } [ "kernel32" find-library "kernel32.dll" find-subseq? ] unit-test
<PRIVATE
: read1-ignoring ( ignoring stream -- ch )
- dup stream-read1 pick dupd member-eq?
+ dup stream-read1 pick over member-eq-of?
[ drop read1-ignoring ] [ 2nip ] if ; inline recursive
: read-ignoring ( n ignoring stream -- accum )
"." write flush
{
- member-eq? split harvest sift cut cut-slice subseq-start index clone
- set-at reverse push-all class-of number>string string>number
+ member-eq? split harvest sift cut cut-slice subseq-start find-subseq
+ index clone set-at reverse push-all class-of number>string string>number
like clone-like
} compile-unoptimized
: running.app? ( -- ? )
! Test if we're running a .app.
- ".app"
NSBundle -> mainBundle -> bundlePath CF>string
- subseq? ;
+ ".app" tail? ;
: assert.app ( message -- )
running.app? [
[ { array } declare dup 1 slot [ 1 slot ] when ]
[ [ dup more? ] [ dup ] produce ]
[ vector new over test-case-1 [ test-case-2 ] [ ] if ]
- [ [ [ nth-unsafe ".." = 0 ] dip set-nth-unsafe ] 2curry (each-integer) ]
+ [ [ [ nth-unsafe ".." = 0 ] dip set-nth-unsafe ] 2curry each-integer-from ]
[
{ fixnum sbuf } declare 2dup 3 slot fixnum> [
over 3 fixnum* over dup [ 2 slot resize-string ] dip 2 set-slot
ERROR: bad-successors ;
: check-successors ( bb -- )
- dup successors>> [ predecessors>> member-eq? ] with all?
+ dup successors>> '[ _ predecessors>> member-eq-of? ] all?
[ bad-successors ] unless ;
: check-cfg ( cfg -- )
my-new-key4
set-slot
]
- curry (each-integer) ;
+ curry each-integer-from ;
{ } [ [ call-recursive-dce-5 swap ] optimize-quot drop ] unit-test
-{ } [ [ [ 0 -rot set-nth-unsafe ] curry (each-integer) ] optimize-quot drop ] unit-test
+{ } [ [ [ 0 -rot set-nth-unsafe ] curry each-integer-from ] optimize-quot drop ] unit-test
: call-recursive-dce-6 ( i quot: ( ..a -- ..b ) -- i )
dup call [ drop ] [ call-recursive-dce-6 ] if ; inline recursive
{ } [ [ [ ] [ ] compose curry call ] final-info drop ] unit-test
{ V{ } } [
- [ [ drop ] [ drop ] compose curry (each-integer) ] final-classes
+ [ [ drop ] [ drop ] compose curry each-integer-from ] final-classes
] unit-test
GENERIC: iterate ( obj -- next-obj ? )
{ t } [
[ [ loop-test-1 ] each ] build-tree analyze-recursive
- \ (each-integer) label-is-loop?
+ \ each-integer-from label-is-loop?
] unit-test
: loop-test-2 ( a b -- a' )
{ t } [
[ 10 [ [ drop ] each-integer ] loop-in-non-loop ]
build-tree analyze-recursive
- \ (each-integer) label-is-loop?
+ \ each-integer-from label-is-loop?
] unit-test
DEFER: a'''
"sql-spec" get modifiers>> [ +not-null+ = ] none? ;
: delete-cascade? ( -- ? )
- "sql-spec" get modifiers>> { +on-delete+ +cascade+ } swap subseq? ;
+ "sql-spec" get modifiers>> { +on-delete+ +cascade+ } find-subseq? ;
: sqlite-trigger, ( string -- )
{ } { } <simple-statement> 3, ;
ERROR: domain-name-contains-empty-label domain ;
: check-domain-name ( domain -- domain )
- ".." over subseq? [ domain-name-contains-empty-label ] when ;
+ dup ".." find-subseq? [ domain-name-contains-empty-label ] when ;
: >dotted ( domain -- domain' )
dup "." tail? [ "." append ] unless ;
{ "git-checkout-existing-branch" { "git-checkout-existing" "0.99" } }
{ "git-checkout-existing-branch*" { "git-checkout-existing*" "0.99" } }
{ "tags" { "chloe-tags" "0.99" } }
+ { "(each-integer)" { "each-integer-from" "0.99" } }
+ { "(find-integer)" { "find-integer-from" "0.99" } }
+ { "(all-integers?)" { "all-integers-from?" "0.99" } }
}
: compute-assoc-fixups ( continuation name assoc -- seq )
[ first2-unsafe ] dip call
] [
[ [ first-unsafe 1 ] [ setup-each [ + ] 2dip ] bi ] dip
- '[ @ _ keep swap ] (all-integers?) nip
+ '[ @ _ keep swap ] all-integers-from? nip
] if
] if ; inline
" white-space: pre-wrap; line-height: 125%;" append
] re-replace-with
- { "font-family: monospace;" "background-color:" } [ over subseq? ] all? [
- " margin: 10px 0px;" append
- ] when
+ { "font-family: monospace;" "background-color:" } [ find-subseq? ] with all?[
+ " margin: 10px 0px;" append
+ ] when
- { "border:" "background-color:" } [ over subseq? ] all? [
+ dup { "border:" "background-color:" } [ find-subseq? ] with all? [
" border-radius: 5px;" append
] when ;
: fix-help-header ( classes -- classes )
dup [
- [ ".a" head? ] [ "#f4efd9;" swap subseq? ] bi and
+ [ ".a" head? ] [ "#f4efd9;" find-subseq? ] 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
- "{ }" over subseq? [ drop f ] when
+ dup "{ }" find-subseq? [ drop f ] when
] map harvest append "}" suffix ;
: css-classes ( classes -- stylesheet )
] each classes sort-values css-classes body ;
: retina-image ( path -- path' )
- "@2x" over subseq? [ "." split1-last "@2x." glue ] unless ;
+ dup "@2x" find-subseq? [ "." split1-last "@2x." glue ] unless ;
: ?copy-file ( from to -- )
dup file-exists? [ 2drop ] [ copy-file ] if ;
simple-lint-error
] when
] [
- " " swap subseq? [
+ " " find-subseq? [
"Paragraph text should not contain double spaces"
simple-lint-error
] when
first [
{ [ CHAR: space = ] [ CHAR: " = ] } 1||
] trim-head
- " " swap subseq?
+ " " find-subseq?
] filter
[ drop ] [
swap <pathname> .
search-words [ { } ] [
[ all-articles ] dip
dup length 1 > [
- '[ article-words _ swap subseq? ] filter
+ '[ article-words _ find-subseq? ] filter
] [
first '[ article-words [ _ head? ] any? ] filter
] if
DEFER: <% delimiter
: check-<% ( lexer -- col )
- "<%" swap [ line-text>> ] [ column>> ] bi subseq-start-from ;
+ [ column>> ] [ line-text>> ] bi "<%" find-subseq-from ;
: found-<% ( accum lexer col -- accum )
[
! hit the velox.ch website.
! { t } [
! "https://alice.sni.velox.ch" http-get nip
- ! [ "Great!" swap subseq? ]
- ! [ "TLS SNI Test Site: alice.sni.velox.ch" swap subseq? ] bi and
+ ! [ "Great!" find-subseq? ]
+ ! [ "TLS SNI Test Site: alice.sni.velox.ch" find-subseq? ] bi and
! ] unit-test
{ t } [
[
swap [ [ pos>> ] [ fill>> ] [ ptr>> ] tri ] dip
[ swap alien-unsigned-1 ] [ member-eq? ] bi-curry*
- compose (find-integer)
+ compose find-integer-from
] [
[ pos>> - ] curry [ f ] if*
] bi ; inline
: unshaped-cols-iota ( matrix -- cols-iota )
[ first-unsafe length ] keep
- [ length min ] 1 (each-from) (each-integer) <iota> ; inline
+ [ length min ] 1 (each-from) each-integer-from <iota> ; inline
: generic-anti-transpose-unsafe ( cols-iota matrix -- newmatrix )
[ <reversed> [ nth-end-unsafe ] with { } map-as ] curry { } map-as ; inline
:: (scan-multiline-string) ( i end lexer -- j )
lexer line-text>> :> text
lexer still-parsing? [
- end text i subseq-start-from [| j |
+ i text end find-subseq-from [| j |
i j text subseq % j end length +
] [
text i short tail % CHAR: \n ,
: message ( -- str )
55 [ "hello" ] replicate concat ;
-{ f } [ message >quoted "=\r\n" swap subseq? ] unit-test
+{ f } [ message >quoted "=\r\n" find-subseq? ] unit-test
{ 1 } [ message >quoted split-lines length ] unit-test
-{ t } [ message >quoted-lines "=\r\n" swap subseq? ] unit-test
+{ t } [ message >quoted-lines "=\r\n" find-subseq? ] unit-test
{ 4 } [ message >quoted-lines split-lines length ] unit-test
{ "===o" } [ message >quoted-lines split-lines [ last ] "" map-as ] unit-test
MACRO: nmap-reduce ( map-quot reduce-quot n -- quot )
-rot dupd compose overd over '[
[ [ first ] _ napply @ 1 ] _ nkeep
- _ _ (neach) (each-integer)
+ _ _ (neach) each-integer-from
] ;
: nall? ( seqs... quot n -- ? )
: insertion-sort ( ... seq quot: ( ... elt -- ... elt' ) -- ... )
! quot is a transformation on elements
- over length [ insert ] 2with 1 -rot (each-integer) ; inline
+ over length [ insert ] 2with 1 -rot each-integer-from ; inline
[ 0 swap length ] keep ; inline
: each-byte ( from to bytes quot: ( elt -- ) -- )
- '[ _ nth-unsafe @ ] (each-integer) ; inline
+ '[ _ nth-unsafe @ ] each-integer-from ; inline
: write-bytes ( from to bytes stream -- )
'[ hex-digits nth-unsafe _ stream-write ] each-byte ; inline
! Just verifies that the presented output contains a callstack.
{ t } [
create-test-failure [ error. ] with-string-writer
- "OBJ-CURRENT-THREAD" swap subseq?
+ "OBJ-CURRENT-THREAD" find-subseq?
] unit-test
<PRIVATE
MEMO: cached-image-path ( path -- image )
- [ load-image ] [ "@2x" swap subseq? >>2x? ] bi ;
+ [ load-image ] [ "@2x" find-subseq? >>2x? ] bi ;
PRIVATE>
dup "announce-list" of [ nip first random ] [ "announce" of ] if* ;
: scrape-url ( metainfo -- url/f )
- announce-url "announce" over path>> subseq? [
+ announce-url dup path>> "announce" find-subseq? [
[ "announce" "scrape" replace ] change-path
] [ drop f ] if ;
:: next-block ( peer -- peer )
peer current-index>> [ 1 + ] [ 0 ] if*
peer #pieces>>
- peer bitfield>> '[ _ check-bitfield ] (find-integer)
+ peer bitfield>> '[ _ check-bitfield ] find-integer-from
peer current-index<<
0 peer current-piece>> set-length
peer ;
: directory-entries-without-git ( directory -- entries )
recursive-directory-entries
- [ name>> "/.git/" swap subseq? ] reject ;
\ No newline at end of file
+ [ name>> "/.git/" find-subseq? ] reject ;
\ No newline at end of file
[ has-file-extension? ] filter ;
: without-git-paths ( paths -- paths' )
- [ "/.git/" swap subseq? ] reject ;
+ [ "/.git/" find-subseq? ] reject ;
: without-node-modules-paths ( paths -- paths' )
- [ "/node_modules/" swap subseq? ] reject ;
+ [ "/node_modules/" find-subseq? ] reject ;
: regular-directory-files ( path -- seq )
recursive-directory-files
: gemini-go ( args -- )
present [ DEFAULT-URL ] when-empty
- { [ "://" over subseq? ] [ "gemini://" head? ] } 1||
+ { [ dup "://" find-subseq? ] [ "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* [ subseq? ] [ 2drop f ] if ;
+ "href" attribute* [ swap find-subseq? ] [ 2drop f ] if ;
: find-hrefs ( vector -- vector' )
[ { [ name>> "a" = ] [ "href" attribute? ] } 1&& ] filter sift
M: object lint ( obj -- seq ) drop f ;
M: callable lint ( quot -- seq )
- [ lint-definitions-keys get-global ] dip '[ _ subseq? ] filter ;
+ lint-definitions-keys get-global [ find-subseq? ] 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." swap subseq?
+ dup output>> "not uptodate. Cannot merge." find-subseq?
[ git-repo-corrupted ]
[ rethrow ]
if
: nonce-already-used? ( assoc -- ? )
"error" of
[ "code" of "mwoauth-invalid-authorization" = ]
- [ "info" of "Nonce already used" swap subseq-start ] bi
+ [ "info" of "Nonce already used" find-subseq ] bi
and ;
: readonly? ( assoc -- ? )
] if ;
: parse-weather ( str -- str' )
- "VC" over subseq? [ "VC" "" replace t ] [ f ] if
+ dup "VC" find-subseq? [ "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 )
- search string n subseq-start-from :> n'
+ n string search find-subseq-from :> n'
n' [ n string search subseq-expected-but-got-eof ] unless
n' search length + string
n n' string ?<slice>
: rewind-slice ( n string slice -- n' string )
2nip [ from>> ] [ seq>> ] bi ; inline
-:: take-from? ( n seq subseq -- n'/f seq ? )
- subseq seq n pick length (subseq-start-from) 2nip [
+:: take-from? ( n seq subseq -- n'/f seq ? )
+ n seq subseq subseq-starts-at? [
n subseq length +
seq
t
: <maxlicense> ( -- max ) -1 0 V{ } clone \ maxlicense boa ; inline
-: out? ( line -- ? ) [ "OUT" ] dip subseq? ; inline
+: out? ( line -- ? ) "OUT" find-subseq? ; 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" swap subseq-start [ 9 - ] [ 1 - ] bi ] keep subseq print ;
+ [ "UTC" find-subseq [ 9 - ] [ 1 - ] bi ] keep subseq print ;
MAIN: web-scraping-main
: 3each-from
( ... seq1 seq2 seq3 quot: ( ... elt1 elt2 elt3 -- ... ) i -- ... )
- [ (3each) ] dip -rot (each-integer) ; inline
+ [ (3each) ] dip -rot each-integer-from ; inline
: 3map-reduce
( ..a seq1 seq2 seq3 map-quot: ( ..a elt1 elt2 elt3 -- ..b intermediate ) reduce-quot: ( ..b prev intermediate -- ..a next ) -- ..a result )
[ length 1 - swap - ] [ nth ] bi ; inline
: each-index-from ( ... seq quot: ( ... elt index -- ... ) i -- ... )
- -rot (each-index) (each-integer) ; inline
+ -rot (each-index) each-integer-from ; inline
<PRIVATE
:: (start-all) ( seq subseq increment -- indices )
0
- [ [ subseq seq ] dip subseq-start-from dup ]
+ [ seq subseq find-subseq-from dup ]
[ [ increment + ] keep ] produce nip ;
: start-all ( seq subseq -- indices )
swapd
'[ _ _ stack-set-nth _ _ stack-set-nth ] ;
-! MACRO: stack-filter ( n quot: ( obj -- ? ) -- quot' )
-! selector [ '[ _ ] replicate spread ] dip ;
-
MACRO: stack-map ( n quot: ( obj -- obj' ) -- quot' )
'[ _ ] replicate '[ _ spread ] ;
: name=value ( string -- remain term )
[ unicode:blank? ] trim
- ":`" over subseq? [ (name=value) ] [ f swap ] if ;
+ dup ":`" find-subseq? [ (name=value) ] [ f swap ] if ;
: name/values ( string -- remain terms )
[ dup { [ empty? not ] [ first CHAR: ` = not ] } 1&& ]
: zoneinfo-zones ( -- seq )
raw-zone-map keys
- [ "/" swap subseq? ] partition
+ [ "/" find-subseq? ] partition
[ natural-sort ] bi@ append ;
GENERIC: zone-matches? ( string rule -- ? )
: comparison-day-string ( timestamp string -- timestamp )
{
- { [ ">=" over subseq? ] [ ">=" split1 swap [ string>number >>day ] dip day-abbrev>= ] }
- { [ "<=" over subseq? ] [ "<=" split1 swap [ string>number >>day ] dip day-abbrev<= ] }
+ { [ dup ">=" find-subseq? ] [ ">=" split1 swap [ string>number >>day ] dip day-abbrev>= ] }
+ { [ dup "<=" find-subseq? ] [ "<=" split1 swap [ string>number >>day ] dip day-abbrev<= ] }
[ string>number >>day ]
} cond ;