Paste: style question

Author: ben_m
Mode: factor
Date: Fri, 5 Feb 2010 00:08:53
Plain Text |
! these functions take x and y and then produce
! y rows of x values (values increasing from 1)

: make-table ( x y -- table )
    over * [1,b] swap group ;

: make-table ( x y -- table )
    [ * [1,b] ] [ drop group ] 2bi ;

Annotation: sample output

Author: ben_m
Mode: factor
Date: Fri, 5 Feb 2010 00:09:59
Plain Text |
( scratchpad ) 2 5 make-table .
{ { 1 2 } { 3 4 } { 5 6 } { 7 8 } { 9 10 } }

Annotation: whole source

Author: ben_m
Mode: factor
Date: Fri, 5 Feb 2010 00:13:07
Plain Text |
! Copyright (C) 2010 Benjamin Meinl.
! See http://factorcode.org/license.txt for BSD license.
USING: grouping io kernel locals math math.parser math.ranges
sequences ;
IN: print-table

: dimensions ( table -- x y )
    [ length ] [ first length ] bi ;

: digits ( n -- n )
    number>string length ;

: pad ( n n -- str )
    [ number>string ] dip CHAR: space pad-head ;

: make-table ( x y -- table )
    [ * [1,b] ] 2keep drop group ;

: print-table ( table -- )
    dup dimensions * digits
    [
        [ pad ] curry map " " join print
    ] curry each ;

New Annotation

Summary:
Author:
Mode:
Body: