Paste: table-block (please suggest simplifications)

Author: randy7
Mode: factor
Date: Mon, 5 Jan 2009 11:23:11
Plain Text |
USING: math.ranges ;

: take-one ( seq-table horizontal-n vertical-n -- item )
[ swap nth ] [ swap nth ] bi* ;


! : last-range ( range -- n ) [ from>> ] [ [ length>> 1- ] [ step>> ]  bi *  ] bi  + ;
    
: extract2 ( range -- n1 n2 )
    [ first 1- ] [ second 1- ] bi ;

: x-range ( x1 x2 -- range ) 1+ 2array ;
: y-range ( y1 y2 -- range ) 1+ 2array ;    
    
: take-few ( seq-table horizontal-range vertical-range -- block )
    swap [ '[ _ extract2 ] dip subseq ] dip 
    '[ [ _ extract2 ] dip subseq ] map
    concat ;       ! basically: v{ 1 2 } seq subseq  ->  seq' [ h{ 2 3 } item subseq ] map
    

! example: 
{
    { 1 2 3 }
    { 4 5 6 }
    { 7 8 9 }
}
    
1 2 x-range
1 2 y-range take-few ! => { 1 2 4 5 }

Annotation: same coord semantics for take-one

Author: randy7
Mode: factor
Date: Mon, 5 Jan 2009 11:27:53
Plain Text |
: take-one ( seq-table horizontal-n vertical-n -- item )
[ 1- ] bi@
[ swap nth ] [ swap nth ] bi* ;

New Annotation

Summary:
Author:
Mode:
Body: