Paste: tetha iteration problem

Author: elasticdog
Mode: factor
Date: Tue, 28 Apr 2009 15:38:44
Plain Text |
: next-iteration ( n -- m )
    dup even? [ 2 / ] [ 3 * 1 + ] if ;

: (chain) ( count n -- count )
    dup 1 = [ drop ] [ next-iteration [ 1+ ] dip (chain) ] if ;

: chain ( n -- count )
    [ 0 ] dip (chain) ;


! (scratchpad) 4 chain .
2

Annotation: alternative using produce

Author: elasticdog
Mode: factor
Date: Tue, 28 Apr 2009 15:54:25
Plain Text |
: next-iteration ( n -- m )
    dup even? [ 2 / ] [ 3 * 1 + ] if ;

: chain ( n -- count )
    [ dup 1 = not ] [ next-iteration dup ] produce nip length ;

! ( scratchpad ) 4 chain .
2

New Annotation

Summary:
Author:
Mode:
Body: