Paste: Joy binrec

Author: CapitalEx
Mode: factor
Date: Tue, 9 May 2023 05:04:41
Plain Text |
USING: kernel math prettyprint random sequences shuffle ;
IN: joy.rec


: binrec-y ( pred true false final quote -- quot )
    [ '[ [ dup call call ] curry _ _ _ _ ] ] 
        dip compose dup call ; inline

: [binrec] ( biny pred true false final -- quote )
    [ roll ] dip '[ dup @ _ [ @ [ @ ] bi@  @ ] if ] ;

: binrec ( x pred true false final -- result )
    [ [binrec] ] binrec-y call( in -- out ) ; 

: b-fib ( n -- n )
    [ 1 <= ] [ ] [ 1 - dup 1 - ] [ + ] binrec ;

: r-fib ( n -- n )
    dup 1 <= [ ] [ 1 - dup 1 - [ r-fib ] bi@ + ] if ;

: b-qsort ( seq -- seq )
    [ length 1 <= ] 
    [ ] 
    [ unclip [ '[ _ > ] partition ] keep -rot ] 
    [ rot suffix prepend ] binrec ;


: r-qsort ( seq -- seq )
    dup length 1 <= [ ] [ 
        unclip [ '[ _ > ] partition ] keep -rot 
            [ r-qsort ] bi@ 
        rot suffix prepend
    ] if ;

Annotation: [binrec] with [ roll ] dip removed

Author: CapitalEx
Mode: factor
Date: Tue, 9 May 2023 14:11:22
Plain Text |
: binrec-y ( pred true false final quote -- quot )
    [ '[ [ dup call call ] curry _ swap _ swap _ swap _ ] ] 
        dip compose dup call ; inline

: [binrec] ( biny pred true false final -- quote )
    '[ dup @ _ [ @ [ @ ] bi@  @ ] if ] ;

: binrec ( x pred true false final -- result )
    [ [binrec] ] binrec-y call( in -- out ) ; 

New Annotation

Summary:
Author:
Mode:
Body: