Re: [Factor-talk] [PATCH, was: Re: cleave, 2cleave, and spread] Use more combinators
> "Slava" == Slava Pestov <[EMAIL PROTECTED]> writes: Slava> Using bi with quotations that take > 1 value from the stack Slava> is not idiomatic. Yeah, that's my feeling too. You can get a partial cleanup from git://www.rfc1149.net/factor.git for-slava Sam -- Samuel Tardieu -- [EMAIL PROTECTED] -- http://www.rfc1149.net/ - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] [PATCH, was: Re: cleave, 2cleave, and spread] Use more combinators
Hi, Using bi with quotations that take > 1 value from the stack is not idiomatic. Slava On Apr 4, 2008, at 3:33 AM, Samuel Tardieu wrote: > --- > I replaced uses of "keep" by "bi" in those two files. I cannot tell > whether I prefer the one or the other, as using "bi" with quotations > returning more than one value on the stack may seem strange, but I'm > getting slowly used to it. > > Feel free to "git am" if you wish, this message should be in the > right format. > > extra/math/primes/primes.factor|8 > extra/project-euler/169/169.factor |2 +- > 2 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/extra/math/primes/primes.factor b/extra/math/primes/ > primes.factor > index 685124e..1c14715 100644 > --- a/extra/math/primes/primes.factor > +++ b/extra/math/primes/primes.factor > @@ -13,7 +13,7 @@ PRIVATE> > > : next-prime ( n -- p ) > dup 83 < [ > -primes-under-million [ [ <=> ] binsearch 1+ ] keep nth > +primes-under-million [ [ <=> ] binsearch 1+ ] [ nth ] bi > ] [ > next-odd find-prime-miller-rabin > ] if ; foldable > @@ -37,7 +37,7 @@ PRIVATE> > { > { [ dup 2 < ] [ drop { } ] } > { [ dup 103 < ] > - [ primes-under-million [ [ <=> ] binsearch 1+ 0 swap ] keep > ] } > + [ primes-under-million [ [ <=> ] binsearch 1+ 0 swap ] > [ ] bi ] } > { [ t ] > [ primes-under-million 103 lprimes-from > rot [ <= ] curry lwhile list>array append ] } > @@ -45,7 +45,7 @@ PRIVATE> > > : primes-between ( low high -- seq ) > primes-upto > - >r 1- next-prime r> > - [ [ <=> ] binsearch ] keep [ length ] keep ; foldable > + [ 1- next-prime ] dip > + [ [ <=> ] binsearch ] [ length ] [ ] tri ; foldable > > : coprime? ( a b -- ? ) gcd nip 1 = ; foldable > diff --git a/extra/project-euler/169/169.factor b/extra/project- > euler/169/169.factor > index 61645bf..d699af3 100644 > --- a/extra/project-euler/169/169.factor > +++ b/extra/project-euler/169/169.factor > @@ -30,7 +30,7 @@ MEMO: fn ( n -- x ) > { > { [ dup 2 < ] [ drop 1 ] } > { [ dup odd? ] [ 2/ fn ] } > -{ [ t ][ 2/ [ fn ] keep 1- fn + ] } > +{ [ t ][ 2/ [ fn ] [ 1- fn ] bi + ] } > } cond ; > > : euler169 ( -- result ) > -- > 1.5.5.rc2.155.gb0a67 > > > > - > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] [PATCH, was: Re: cleave, 2cleave, and spread] Use more combinators
--- I replaced uses of "keep" by "bi" in those two files. I cannot tell whether I prefer the one or the other, as using "bi" with quotations returning more than one value on the stack may seem strange, but I'm getting slowly used to it. Feel free to "git am" if you wish, this message should be in the right format. extra/math/primes/primes.factor|8 extra/project-euler/169/169.factor |2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/extra/math/primes/primes.factor b/extra/math/primes/primes.factor index 685124e..1c14715 100644 --- a/extra/math/primes/primes.factor +++ b/extra/math/primes/primes.factor @@ -13,7 +13,7 @@ PRIVATE> : next-prime ( n -- p ) dup 83 < [ -primes-under-million [ [ <=> ] binsearch 1+ ] keep nth +primes-under-million [ [ <=> ] binsearch 1+ ] [ nth ] bi ] [ next-odd find-prime-miller-rabin ] if ; foldable @@ -37,7 +37,7 @@ PRIVATE> { { [ dup 2 < ] [ drop { } ] } { [ dup 103 < ] - [ primes-under-million [ [ <=> ] binsearch 1+ 0 swap ] keep ] } + [ primes-under-million [ [ <=> ] binsearch 1+ 0 swap ] [ ] bi ] } { [ t ] [ primes-under-million 103 lprimes-from rot [ <= ] curry lwhile list>array append ] } @@ -45,7 +45,7 @@ PRIVATE> : primes-between ( low high -- seq ) primes-upto - >r 1- next-prime r> - [ [ <=> ] binsearch ] keep [ length ] keep ; foldable + [ 1- next-prime ] dip + [ [ <=> ] binsearch ] [ length ] [ ] tri ; foldable : coprime? ( a b -- ? ) gcd nip 1 = ; foldable diff --git a/extra/project-euler/169/169.factor b/extra/project-euler/169/169.factor index 61645bf..d699af3 100644 --- a/extra/project-euler/169/169.factor +++ b/extra/project-euler/169/169.factor @@ -30,7 +30,7 @@ MEMO: fn ( n -- x ) { { [ dup 2 < ] [ drop 1 ] } { [ dup odd? ] [ 2/ fn ] } -{ [ t ][ 2/ [ fn ] keep 1- fn + ] } +{ [ t ][ 2/ [ fn ] [ 1- fn ] bi + ] } } cond ; : euler169 ( -- result ) -- 1.5.5.rc2.155.gb0a67 - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk