Paste: diamond update

Author: yac
Mode: factor
Date: Tue, 17 May 2011 17:34:35
Plain Text |
#! /usr/bin/env factor
USING: kernel io math math.ranges sequences strings arrays command-line namespaces ;
IN: diamond

: >index ( index -- letter ) CHAR: A - 1 + ;
: n-spc ( n -- str ) [ CHAR: \s ] "" replicate-as ;
: half-line* ( n i -- inner char outer )
    [ - ] keep dup >index 1 - ;
: half-line ( n i -- str )
    half-line* [ n-spc ] [ 1string ] [ n-spc ] tri* 3append ;
: mirror ( seq -- seq2 ) dup reverse rest append ;
: line ( n i -- str ) half-line mirror "\n" append ;
: half-diamond ( n -- str ) 
    CHAR: A over [a,b] [ line ] with map ;
: diamond ( n -- str ) half-diamond mirror concat ;
    
command-line get dup length 1 =
    [ first first diamond print ]
    [ "Give me a letter as only argument, dear sir." print ]
if                                                          

New Annotation

Summary:
Author:
Mode:
Body: