using if-zero in more places.

db4
John Benediktsson 2012-07-16 15:45:21 -07:00
parent 80a7329de8
commit 5cc30f46f5
6 changed files with 15 additions and 14 deletions

View File

@ -165,7 +165,7 @@ M: secure (accept)
{ SSL_ERROR_NONE [ 2drop f ] } { SSL_ERROR_NONE [ 2drop f ] }
{ SSL_ERROR_WANT_READ [ 2drop +input+ ] } { SSL_ERROR_WANT_READ [ 2drop +input+ ] }
{ SSL_ERROR_WANT_WRITE [ 2drop +output+ ] } { SSL_ERROR_WANT_WRITE [ 2drop +output+ ] }
{ SSL_ERROR_SYSCALL [ dup zero? [ 2drop f ] [ syscall-error ] if ] } { SSL_ERROR_SYSCALL [ [ drop f ] [ syscall-error ] if-zero ] }
{ SSL_ERROR_SSL [ (ssl-error) ] } { SSL_ERROR_SSL [ (ssl-error) ] }
} case ; } case ;

View File

@ -48,11 +48,11 @@ PRIVATE>
swap <repetition> seq ; swap <repetition> seq ;
: at-most-n ( parser n -- parser' ) : at-most-n ( parser n -- parser' )
dup zero? [ [
2drop epsilon drop epsilon
] [ ] [
[ exactly-n ] [ 1 - at-most-n ] 2bi 2choice [ exactly-n ] [ 1 - at-most-n ] 2bi 2choice
] if ; ] if-zero ;
: at-least-n ( parser n -- parser' ) : at-least-n ( parser n -- parser' )
dupd exactly-n swap repeat0 2seq dupd exactly-n swap repeat0 2seq

View File

@ -59,8 +59,8 @@ M: maybe vocabulary-name
] if ; ] if ;
: text-fits? ( len -- ? ) : text-fits? ( len -- ? )
margin get dup zero? margin get
[ 2drop t ] [ [ pprinter get indent>> + ] dip <= ] if ; [ drop t ] [ [ pprinter get indent>> + ] dip <= ] if-zero ;
! break only if position margin 2 / > ! break only if position margin 2 / >
SYMBOL: soft SYMBOL: soft

View File

@ -54,10 +54,9 @@ M: at-least <times>
n>> swap [ repetition ] [ <star> ] bi 2array <concatenation> ; n>> swap [ repetition ] [ <star> ] bi 2array <concatenation> ;
: to-times ( term n -- ast ) : to-times ( term n -- ast )
dup zero? [ drop epsilon ]
[ 2drop epsilon ]
[ dupd 1 - to-times 2array <concatenation> <maybe> ] [ dupd 1 - to-times 2array <concatenation> <maybe> ]
if ; if-zero ;
M: from-to <times> M: from-to <times>
[ n>> swap repetition ] [ n>> swap repetition ]

View File

@ -5,18 +5,20 @@ IN: math.continued-fractions
<PRIVATE <PRIVATE
: split-float ( f -- d i ) dup >integer [ - ] keep ; : split-float ( f -- d i )
dup >integer [ - ] keep ;
: closest ( seq -- newseq ) unclip-last round >integer suffix ; : closest ( seq -- newseq )
unclip-last round >integer suffix ;
PRIVATE> PRIVATE>
: next-approx ( seq -- ) : next-approx ( seq -- )
dup [ pop split-float ] [ push ] bi dup [ pop split-float ] [ push ] bi
dup zero? [ 2drop ] [ recip swap push ] if ; [ drop ] [ recip swap push ] if-zero ;
: >ratio ( seq -- a/b ) : >ratio ( seq -- a/b )
closest reverse unclip-slice [ swap recip + ] reduce ; closest reverse! unclip-slice [ swap recip + ] reduce ;
: approx ( epsilon float -- a/b ) : approx ( epsilon float -- a/b )
dup 1vector dup 1vector

View File

@ -53,5 +53,5 @@ IN: math.floating-point
[ (double-sign) zero? 1 -1 ? ] [ (double-sign) zero? 1 -1 ? ]
[ (double-mantissa-bits) 52 2^ / ] [ (double-mantissa-bits) 52 2^ / ]
[ (double-exponent-bits) ] tri [ (double-exponent-bits) ] tri
dup zero? [ 1 + ] [ [ 1 + ] dip ] if 1023 - 2 swap ^ * * ; [ 1 ] [ [ 1 + ] dip ] if-zero 1023 - 2 swap ^ * * ;