[ 2drop 0 < ]
[ [ drop ] 2dip length > ]
[ drop > ]
- } 3|| [ 3drop f ] [ slice boa ] if swap [ [ length ] bi@ ] 2keep ;
+ } 3|| [ 3drop f ] [ slice boa ] if swap [ 2length ] 2keep ;
{ 0 3 f { 1 2 3 } } [ { 1 2 3 } -10 3 "hello" coalescing-bug-1 ] unit-test
{ 0 3 f { 1 2 3 } } [ { 1 2 3 } 0 7 "hello" coalescing-bug-1 ] unit-test
{
{ [ dup not ] [ ] }
{ [ dup ends-with-terminate? ] [ out-d [ f swap <#push> ] map append ] }
- [ in-d' out-d [ [ length ] bi@ assert= ] [ <#copy> suffix ] 2bi ]
+ [ in-d' out-d [ 2length assert= ] [ <#copy> suffix ] 2bi ]
} cond
] [ inference-error? ] ignore-error/f ;
: congruent? ( alloc1 alloc2 -- ? )
{
{ [ 2dup [ boolean? ] either? ] [ eq? ] }
- { [ 2dup [ length ] bi@ = not ] [ 2drop f ] }
+ { [ 2dup 2length @ = not ] [ 2drop f ] }
[ [ [ allocation ] bi@ congruent? ] 2all? ]
} cond ;
[
[ nip ] [
dup [ +top+ eq? ] trim-head
- [ [ length ] bi@ - tail* ] keep append
+ [ 2length - tail* ] keep append
] if
] 3map ;
ERROR: invalid-outputs #call infos ;
: check-outputs ( #call infos -- infos )
- over out-d>> over [ length ] bi@ =
+ over out-d>> over 2length =
[ nip ] [ invalid-outputs ] if ;
: call-outputs-quot ( #call word -- infos )
! preserve file traversal order, but sort
! alphabetically for cross-platform testing
- [ [ length ] bi@ = ] monotonic-split
+ [ 2length = ] monotonic-split
[ sort ] map concat
] with-variable
] with-test-directory
[ [ parse-ipv4 append ] unless-empty ] bi* ;
: pad-ipv6 ( string1 string2 -- seq )
- 2dup [ length ] bi@ + 8 swap -
+ 2dup 2length + 8 swap -
dup 0 < [ more-than-8-components ] when
<byte-array> glue ;
ALIAS: n*p n*v
: pextend-conv ( p q -- p' q' )
- 2dup [ length ] bi@ + 1 - 2pad-tail ;
+ 2dup 2length + 1 - 2pad-tail ;
: p* ( p q -- r )
2unempty pextend-conv
: p/mod-setup ( p p -- p p n )
2ptrim
- 2dup [ length ] bi@ -
+ 2dup 2length -
dup 1 < [ drop 1 ] when
[ over length + 0 pad-head pextend ] keep 1 + ;
[ mime-write ]
[ swap length tail-slice >>bytes ] bi*
] [
- tuck [ length ] bi@ - 1 - cut-slice
+ tuck 2length - 1 - cut-slice
[ mime-write ]
[ >>bytes ] bi* fill-bytes
dup end-of-stream?>> [ dump-until-separator ] unless
: score ( full fuzzy -- n )
[
- [ [ length ] bi@ - 15 swap [-] 3 /f ] 2keep
+ [ 2length - 15 swap [-] 3 /f ] 2keep
runs [
[ 0 [ pick score-1 max ] reduce nip ] keep
length * +
: take-string ( match -- string )
[ spot get (take-string) [ missing-close ] unless ]
- [ dupd [ length ] bi@ - over shorten "" like ] bi ;
+ [ dupd 2length - over shorten "" like ] bi ;
: expect ( string -- )
dup length spot get '[ _ [ char>> ] keep next* ] "" replicate-as
] if-bootstrapping ; inline
: pad-slots ( seq class -- seq' class )
- [ all-slots ] keep 2over [ length ] bi@ 2dup > [
+ [ all-slots ] keep 2over 2length 2dup > [
[ nip swap ] 2dip too-many-slots
] [
drop [
! See https://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs kernel kernel.private math
math.order math.private quotations sequences sequences.private
-sets sorting words ;
+sets words ;
IN: combinators
! Most of these combinators have compile-time expansions in
: change-nth ( ..a i seq quot: ( ..a elt -- ..b newelt ) -- ..b )
[ [ nth ] dip call ] 2keepd set-nth-unsafe ; inline
-: min-length ( seq1 seq2 -- n ) [ length ] bi@ min ; inline
+: min-length ( seq1 seq2 -- n ) 2length min ; inline
-: max-length ( seq1 seq2 -- n ) [ length ] bi@ max ; inline
+: max-length ( seq1 seq2 -- n ) 2length max ; inline
<PRIVATE
[ nth-unsafe ] tri-curry@ tri ; inline
: setup-3each ( seq1 seq2 seq3 -- n quot )
- [ [ length ] tri@ min min check-length ]
+ [ 3length min min check-length ]
[ [ 3nth-unsafe ] 3curry ] 3bi ; inline
: (3each) ( seq1 seq2 seq3 quot -- n quot' )
[ 2nth-unsafe <=> ] [ [ length ] compare nip ] if ;
: sequence= ( seq1 seq2 -- ? )
- 2dup [ length ] bi@ dupd =
+ 2dup 2length dupd =
[ -rot mismatch-unsafe not ] [ 3drop f ] if ; inline
ERROR: assert-sequence got expected ;
: pad-tail ( seq n elt -- padded )
[ append ] padding ;
-: shorter? ( seq1 seq2 -- ? ) [ length ] bi@ < ; inline
-: longer? ( seq1 seq2 -- ? ) [ length ] bi@ > ; inline
-: shorter ( seq1 seq2 -- seq ) [ [ length ] bi@ <= ] 2keep ? ; inline
-: longer ( seq1 seq2 -- seq ) [ [ length ] bi@ >= ] 2keep ? ; inline
+: shorter? ( seq1 seq2 -- ? ) 2length < ; inline
+: longer? ( seq1 seq2 -- ? ) 2length > ; inline
+: shorter ( seq1 seq2 -- seq ) [ 2length <= ] 2keep ? ; inline
+: longer ( seq1 seq2 -- seq ) [ 2length >= ] 2keep ? ; inline
: head? ( seq begin -- ? )
2dup shorter? [
] with all-integers? ; inline
: subseq-index-from ( n seq subseq -- i/f )
- [ [ length ] bi@ - 1 + ] 2keep
+ [ 2length - 1 + ] 2keep
'[ _ _ subseq-starts-at? ] find-integer-from ; inline
: subseq-index ( seq subseq -- i/f ) [ 0 ] 2dip subseq-index-from ; inline
{ 0 1 } [
{ "benchmark.tests" } [ drop "hello" throw ] run-benchmarks
- [ length ] bi@
+ 2length
] unit-test
remove-nth remove-nth! change-nth
}
] replicate concat [ named completions ] keep
- [ length ] bi@ assert= ;
+ 2length assert= ;
MAIN: completion-benchmark
--- /dev/null
+! Copyright (C) 2010 Maximilian Lupke.
+! See http://factorcode.org/license.txt for BSD license.
+USING: arrays ascii kernel math math.order math.parser sequences
+sorting.human splitting ;
+IN: semantic-versioning
+
+<PRIVATE
+
+: number<=> ( obj1 obj2 -- <=> )
+ [ [ zero? ] trim-tail-slice ] bi@ <=> ;
+
+: pre-release<=> ( obj1 obj2 -- <=> )
+ 2dup [ empty? ] either?
+ [ 2length >=< ] [ human<=> ] if ;
+
+PRIVATE>
+
+: split-version ( string -- array )
+ "+" split1 [
+ dup [ [ digit? not ] [ CHAR: . = not ] bi and ] find [
+ [ cut ] [ CHAR: - = [ rest [ f ] when-empty ] when ] bi*
+ ] [ drop f ] if*
+ [ "." split [ string>number 0 or ] map 3 0 pad-tail ] dip
+ ] dip 3array ;
+
+: version<=> ( version1 version2 -- <=> )
+ [ split-version ] bi@
+ 2dup [ first ] bi@ number<=> dup +eq+ =
+ [ drop [ second ] bi@ pre-release<=> ] [ 2nip ] if ;
+
+: version< ( version1 version2 -- ? )
+ version<=> +lt+ eq? ;
+
+: version<= ( version1 version2 -- ? )
+ version<=> { +lt+ +eq+ } member-eq? ;
+
+: version= ( version1 version2 -- ? )
+ version<=> +eq+ eq? ;
+
+: version>= ( version1 version2 -- ? )
+ version<=> { +gt+ +eq+ } member-eq? ;
+
+: version> ( version1 version2 -- ? )
+ version<=> +gt+ eq? ;
] with-compilation-unit ;
: test-inference ( ast -- in# out# )
- test-compilation infer [ in>> ] [ out>> ] bi [ length ] bi@ ;
+ test-compilation infer [ in>> ] [ out>> ] bi 2length ;
{ 2 1 } [
T{ ast-block f
{ { 0 2 1 } } [ { 10 30 20 } [ <=> ] argsort ] unit-test
{ { 2 0 1 } } [
- { "hello" "goodbye" "yo" } [ [ length ] bi@ <=> ] argsort
+ { "hello" "goodbye" "yo" } [ 2length <=> ] argsort
] unit-test
{ { "blue" "green" "purple" } } [
] [
[ >tensor ] dip
] if
- 2dup [ length ] bi@ = [ shape>> reshape ] [ drop ] if
+ 2dup 2length = [ shape>> reshape ] [ drop ] if
] if ;
syntax:M: tensor clone-like
over tensor?
[ drop clone ] [
[ >tensor ] dip
- 2dup [ length ] bi@ = [ shape>> reshape ] [ drop ] if
+ 2dup 2length = [ shape>> reshape ] [ drop ] if
] if ;
INSTANCE: tensor sequence
}
: zip-names ( seq names -- assoc )
- swap 2dup [ length ] bi@ - f <repetition> append zip ;
+ swap 2dup 2length - f <repetition> append zip ;
PRIVATE>