Paste: first program

Author: yac
Mode: factor
Date: Mon, 16 May 2011 22:41:50
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 ] dip ] dip 3array concat ;
: 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] [ over swap line ] map nip ;
: 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: