[ dup [ 2dup - ] [ f ] if ] dip
gadget-metrics boa ; inline
-: ?supremum ( seq -- n/f )
- sift [ f ] [ supremum ] if-empty ;
+: ?maximum ( seq -- n/f )
+ sift [ f ] [ maximum ] if-empty ;
: max-ascent ( seq -- n/f )
- [ ascent>> ] map ?supremum ;
+ [ ascent>> ] map ?maximum ;
: max-cap-height ( seq -- n/f )
- [ cap-height>> ] map ?supremum ;
+ [ cap-height>> ] map ?maximum ;
: max-descent ( seq -- n/f )
- [ descent>> ] map ?supremum ;
+ [ descent>> ] map ?maximum ;
: max-graphics-height ( seq -- n )
- [ ascent>> ] reject [ height>> ] map ?supremum 0 or ;
+ [ ascent>> ] reject [ height>> ] map ?maximum 0 or ;
:: combine-metrics ( graphics-height ascent descent cap-height -- ascent' descent' )
ascent [
children>> dup pref-dims measure-metrics drop ; inline
: pack-cap-height ( pack -- n/f )
- children>> [ cap-height ] map ?supremum ; inline
+ children>> [ cap-height ] map ?maximum ; inline
PRIVATE>
: partial-sums ( seq -- sums )
cum-sum 0 prefix ; inline
-: partial-sum-infimum ( seq quot -- seq )
+: partial-sum-minimum ( seq quot -- seq )
[ 0 0 ] 2dip [ + [ min ] keep ] compose each drop ; inline
-: map-infimum ( seq quot -- min )
+: map-minimum ( seq quot -- min )
[ min ] compose 0 swap reduce ; inline
! triangle generator functions
x z + table nth-unsafe
[ y z + 1 + swap nth-unsafe ]
[ y swap nth-unsafe ] bi -
- ] partial-sum-infimum
- ] map-infimum
- ] map-infimum ; inline
+ ] partial-sum-minimum
+ ] map-minimum
+ ] map-minimum ; inline
PRIVATE>
{ $description "Outputs a new sequence consisting of " { $snippet "seq" } " padded on the left and right with enough repetitions of " { $snippet "elt" } " to have the result be of length " { $snippet "n" } "." }
{ $examples { $example "USING: io sequences sequences.extras ;" "{ \"ab\" \"quux\" } [ 5 CHAR: - pad-center print ] each" "-ab--\nquux-" } } ;
-HELP: ?supremum
+HELP: ?maximum
{ $values
{ "seq/f" { $maybe sequence } }
{ "elt/f" { $maybe object } }
{ $description "Outputs the greatest element of " { $snippet "seq" } ", ignoring any " { $link POSTPONE: f } " elements in it. If " { $snippet "seq" } " is empty or " { $link POSTPONE: f } ", returns " { $link POSTPONE: f } "." }
{ $examples
{ $example "USING: prettyprint sequences.extras ;"
- "{ 1 f 3 2 } ?supremum ."
+ "{ 1 f 3 2 } ?maximum ."
"3" }
} ;
-HELP: ?infimum
+HELP: ?minimum
{ $values
{ "seq/f" { $maybe sequence } }
{ "elt/f" { $maybe object } }
{ $description "Outputs the least element of " { $snippet "seq" } ", ignoring any " { $link POSTPONE: f } " elements in it. If " { $snippet "seq" } " is empty or " { $link POSTPONE: f } ", returns " { $link POSTPONE: f } "." }
{ $examples
{ $example "USING: prettyprint sequences.extras ;"
- "{ 1 f 3 2 } ?infimum ."
+ "{ 1 f 3 2 } ?minimum ."
"1" }
} ;
-{ ?supremum ?infimum } related-words
+{ ?maximum ?minimum } related-words
HELP: 2count
{ $values
{ V{ 0 4 } } [ { 5 3 2 10 5 } [ 5 = ] arg-where ] unit-test
{ { 2 1 0 4 3 } } [ { 5 3 2 10 5 } arg-sort ] unit-test
-{ 10 } [ { 4 3 2 1 } [ 10 * ] map-infimum ] unit-test
-{ 40 } [ { 4 3 2 1 } [ 10 * ] map-supremum ] unit-test
+{ 10 } [ { 4 3 2 1 } [ 10 * ] map-minimum ] unit-test
+{ 40 } [ { 4 3 2 1 } [ 10 * ] map-maximum ] unit-test
{ t } [ { 1 2 3 4 5 } 1 first= ] unit-test
{ t } [ { 1 2 3 4 5 } 2 second= ] unit-test
{ 1 "beef" } [ { "chicken" "beef" "moose" } [ length ] minimum-by* ] unit-test
{ 0 "chicken" } [ { "chicken" "beef" "moose" } [ length ] maximum-by* ] unit-test
{ 2 "moose" } [ { "chicken" "beef" "moose" } [ first ] maximum-by* ] unit-test
-{ f } [ f ?supremum ] unit-test
-{ f } [ { } ?supremum ] unit-test
-{ f } [ { f } ?supremum ] unit-test
-{ 3 } [ { 1 f 3 2 } ?supremum ] unit-test
-{ 3 } [ { 1 3 2 } ?supremum ] unit-test
-{ f } [ f ?infimum ] unit-test
-{ f } [ { } ?infimum ] unit-test
-{ f } [ { f } ?infimum ] unit-test
-{ 1 } [ { 1 f 3 2 } ?infimum ] unit-test
-{ 1 } [ { 1 3 2 } ?infimum ] unit-test
+{ f } [ f ?maximum ] unit-test
+{ f } [ { } ?maximum ] unit-test
+{ f } [ { f } ?maximum ] unit-test
+{ 3 } [ { 1 f 3 2 } ?maximum ] unit-test
+{ 3 } [ { 1 3 2 } ?maximum ] unit-test
+{ f } [ f ?minimum ] unit-test
+{ f } [ { } ?minimum ] unit-test
+{ f } [ { f } ?minimum ] unit-test
+{ 1 } [ { 1 f 3 2 } ?minimum ] unit-test
+{ 1 } [ { 1 3 2 } ?minimum ] unit-test
{ 3/10 } [ 10 <iota> [ 3 < ] percent-of ] unit-test
: arg-min ( seq -- n )
[ ] minimum-by* drop ;
-: ?supremum ( seq/f -- elt/f )
+: ?maximum ( seq/f -- elt/f )
[ f ] [
[ ] [ 2dup and [ max ] [ dupd ? ] if ] map-reduce
] if-empty ;
-: ?infimum ( seq/f -- elt/f )
+: ?minimum ( seq/f -- elt/f )
[ f ] [
[ ] [ 2dup and [ min ] [ dupd ? ] if ] map-reduce
] if-empty ;
-: map-infimum ( seq quot: ( ... elt -- ... elt' ) -- elt' )
+ALIAS: ?supremum ?maximum deprecated
+ALIAS: ?infimum ?minimum deprecated
+
+: map-minimum ( seq quot: ( ... elt -- ... elt' ) -- elt' )
[ min ] map-reduce ; inline
-: map-supremum ( seq quot: ( ... elt -- ... elt' ) -- elt' )
+: map-maximum ( seq quot: ( ... elt -- ... elt' ) -- elt' )
[ max ] map-reduce ; inline
+ALIAS: map-supremum map-maximum deprecated
+ALIAS: map-infimum map-minimum deprecated
+
: change-last ( seq quot -- )
[ index-of-last ] [ change-nth ] bi* ; inline