[ amb-integer ] [ nth ] bi ;\r
\r
: amb ( seq -- elt )\r
- dup empty?\r
- [ drop fail f ]\r
- [ unsafe-amb ] if ; inline\r
+ [ fail f ]\r
+ [ unsafe-amb ] if-empty ; inline\r
\r
MACRO: amb-execute ( seq -- quot )\r
[ length 1 - ] [ <enum> [ 1quotation ] assoc-map ] bi\r
[ first - ] [ second ] bi ;
M: multi-cord virtual-seq
- seqs>> dup empty? [ drop f ] [ first second ] if ;
+ seqs>> [ f ] [ first second ] if-empty ;
: <cord> ( seqs -- cord )
dup length 2 = [
buttons-matching-hash device-elements-matching length ;
: ?axis ( device hash -- axis/f )
- device-elements-matching dup empty? [ drop f ] [ first ] if ;
+ device-elements-matching [ f ] [ first ] if-empty ;
: ?x-axis ( device -- ? )
x-axis-matching-hash ?axis ;
[ get-char CHAR: < = ] take-until ;
: parse-text ( -- )
- read-until-< dup empty? [
- drop
- ] [
+ read-until-< [
make-text-tag push-tag
- ] if ;
+ ] unless-empty ;
: (parse-attributes) ( -- )
read-whitespace*
drop "The word cannot be used in pattern matching" ;
: next ( revquot -- revquot* first )
- dup empty?
[ "Badly formed math inverse" throw ]
- [ unclip-slice ] if ;
+ [ unclip-slice ] if-empty ;
: constant-word? ( word -- ? )
stack-effect
"pop-inverse" word-prop compose call ;
: (undo) ( revquot -- )
- dup empty? [ drop ]
- [ unclip-slice inverse % (undo) ] if ;
+ [ unclip-slice inverse % (undo) ] unless-empty ;
: [undo] ( quot -- undo )
flatten fold reverse [ (undo) ] [ ] make ;
"irc.ui.commands" require\r
\r
: command ( string string -- string command )\r
- dup empty? [ drop "say" ] when\r
+ [ "say" ] when-empty\r
dup "irc.ui.commands" lookup\r
[ nip ]\r
[ " " append prepend "quote" "irc.ui.commands" lookup ] if* ;\r
: dark-green T{ rgba f 0.0 0.5 0.0 1 } ;\r
\r
: dot-or-parens ( string -- string )\r
- dup empty? [ drop "." ]\r
- [ "(" prepend ")" append ] if ;\r
+ [ "." ]\r
+ [ "(" prepend ")" append ] if-empty ;\r
\r
GENERIC: write-irc ( irc-message -- )\r
\r
: x.dy ( x y -- vec ) (d) wedge -1 alt*n ;
: (d) ( product -- value )
- dup empty?
- [ drop H{ } ] [ unclip swap [ x.dy ] 2keep dx.y alt+ ] if ;
+ [ H{ } ] [ unclip swap [ x.dy ] 2keep dx.y alt+ ] if-empty ;
: linear-op ( vec quot -- vec )
[
: m'.m ( matrix -- matrix' ) dup flip swap m. ;
: empty-matrix? ( matrix -- ? )
- dup empty? [ drop t ] [ first empty? ] if ;
+ [ t ] [ first empty? ] if-empty ;
: ?m+ ( m1 m2 -- m3 )
over empty-matrix? [
: 2pad-right ( p p n -- p p ) 0 [ pad-right swap ] 2keep pad-right swap ;
: pextend ( p p -- p p ) 2dup [ length ] bi@ max 2pad-right ;
: pextend-left ( p p -- p p ) 2dup [ length ] bi@ max 2pad-left ;
-: unempty ( seq -- seq ) dup empty? [ drop { 0 } ] when ;
+: unempty ( seq -- seq ) [ { 0 } ] when-empty ;
: 2unempty ( seq seq -- seq seq ) [ unempty ] bi@ ;
PRIVATE>
: (count) ( n d -- n' )
[ (factor) ] { } make
- dup empty? [ drop ] [ [ first ] keep length 2array , ] if ;
+ [ [ first ] keep length 2array , ] unless-empty ;
: (unique) ( n d -- n' )
[ (factor) ] { } make
- dup empty? [ drop ] [ first , ] if ;
+ [ first , ] unless-empty ;
: (factors) ( quot list n -- )
dup 1 > [ swap uncons swap >r pick call r> swap (factors) ] [ 3drop ] if ;
: text-with-scale ( index seq -- str )
dupd nth 3digits>text swap
- scale-numbers dup empty? [
- drop
- ] [
+ scale-numbers [
" " swap 3append
- ] if ;
+ ] unless-empty ;
: append-with-conjunction ( str1 str2 -- newstr )
over length zero? [
: parse-decimal ( str -- ratio )
"." split1
>r dup "-" head? [ drop t "0" ] [ f swap ] if r>
- [ dup empty? [ drop "0" ] when ] bi@
+ [ [ "0" ] when-empty ] bi@
dup length
>r [ dup string>number [ nip ] [ not-a-decimal ] if* ] bi@ r>
10 swap ^ / + swap [ neg ] when ;
dup length <reversed>
[ picker 2array ] 2map
[ drop object eq? not ] assoc-filter
- dup empty? [ drop [ t ] ] [
+ [ [ t ] ] [
[ (multi-predicate) ] { } assoc>map
unclip [ swap [ f ] \ if 3array append [ ] like ] reduce
- ] if ;
+ ] if-empty ;
: argument-count ( methods -- n )
keys 0 [ length max ] reduce ;
"\0" read-until [ drop f ] unless ;
: read-c-string* ( n -- str/f )
- read [ zero? ] trim-right dup empty? [ drop f ] when ;
+ read [ zero? ] trim-right [ f ] when-empty ;
: (read-128-ber) ( n -- n )
read1
} cond ;
: -ion ( str -- newstr )
- dup empty? [
- drop "ion"
+ [
+ "ion"
] [
dup "st" last-is? [ "ion" append ] unless
- ] if ;
+ ] if-empty ;
: step4 ( str -- newstr )
dup {
: find-source ( seq -- elt )
unzip diff prune
- dup empty? [ "Topological sort failed" throw ] [ first ] if ;
+ [ "Topological sort failed" throw ] [ first ] if-empty ;
: remove-source ( seq elt -- seq )
[ swap member? not ] curry filter ;
dup length 1 > [
dup find-source dup , remove-source (topological-sort)
] [
- dup empty? [ drop ] [ first [ , ] each ] if
+ [ first [ , ] each ] unless-empty
] if ;
PRIVATE>
: vocab-noise-factor ( vocab -- factor )\r
words flatten-generics\r
[ word-noise-factor dup 20 < [ drop 0 ] when ] map\r
- dup empty? [ drop 0 ] [\r
+ [ 0 ] [\r
[ [ sum ] [ length 5 max ] bi /i ]\r
[ supremum ]\r
bi +\r
- ] if ;\r
+ ] if-empty ;\r
\r
: noisy-vocabs ( -- alist )\r
vocabs [ dup vocab-noise-factor ] { } map>assoc\r
"passed to the quotation given to each-withn for each element in the sequence."\r
} \r
{ $see-also map-withn } ;\r
-\r
-HELP: if-seq\r
-{ $values { "seq" sequence } { "quot1" quotation } { "quot2" quotation } }\r
-{ $description "Makes an implicit check if the sequence is empty. If the sequence has any elements, " { $snippet "quot1" } " is called on it. Otherwise, the empty sequence is dropped and " { $snippet "quot2" } " is called." }\r
-{ $example\r
- "USING: kernel prettyprint sequences sequences.lib ;"\r
- "{ 1 2 3 } [ sum ] [ \"empty sequence\" throw ] if-seq ."\r
- "6"\r
-} ;\r
-\r
-HELP: if-empty\r
-{ $values { "seq" sequence } { "quot1" quotation } { "quot2" quotation } }\r
-{ $description "Makes an implicit check if the sequence is empty. An empty sequence is dropped and " { $snippet "quot1" } " is called. Otherwise, if the sequence has any elements, " { $snippet "quot2" } " is called on it." }\r
-{ $example\r
- "USING: kernel prettyprint sequences sequences.lib ;"\r
- "{ 1 2 3 } [ \"empty sequence\" ] [ sum ] if-empty ."\r
- "6"\r
-} ;\r
-\r
-{ if-seq if-empty } related-words\r
[ 1 2 { 3 4 } [ + + drop ] 2 each-withn ] must-infer
{ 13 } [ 1 2 { 3 4 } [ + + ] 2 each-withn + ] unit-test
[ { 910 911 912 } ] [ 10 900 3 [ + + ] map-with2 ] unit-test
-
-[ "empty" ] [ { } [ "not empty" ] [ "empty" ] if-seq ] unit-test
-[ { 1 } "not empty" ] [ { 1 } [ "not empty" ] [ "empty" ] if-seq ] unit-test
: ?nth* ( n seq -- elt/f ? )
2dup bounds-check? [ nth-unsafe t ] [ 2drop f f ] if ; flushable
-
-: if-seq ( seq quot1 quot2 -- ) [ f like ] 2dip if* ; inline
-
-: if-empty ( seq quot1 quot2 -- ) swap if-seq ; inline
-
-: when-empty ( seq quot1 -- ) [ ] if-empty ; inline
-
-: unless-empty ( seq quot1 -- ) [ ] swap if-empty ; inline
-
[ remove-one ] curry bi@ ;
: symbolic-reduce ( seq seq -- seq seq )
- 2dup intersect dup empty?
- [ drop ] [ first 2remove-one symbolic-reduce ] if ;
+ 2dup intersect
+ [ first 2remove-one symbolic-reduce ] unless-empty ;
: <dimensioned> ( n top bot -- obj )
symbolic-reduce
DEFER: >>
: attributes-parsed ( accum quot -- accum )
- dup empty? [ drop f parsed ] [
+ [ f parsed ] [
>r \ >r parsed r> parsed
[ H{ } make-assoc r> swap ] [ parsed ] each
- ] if ;
+ ] if-empty ;
: <<
parsed-name [