RosettaCodeData/Task/Comma-quibbling/Factor/comma-quibbling.factor
2019-09-12 10:33:56 -07:00

14 lines
345 B
Factor

USING: inverse qw sequences ;
: (quibble) ( seq -- seq' )
{
{ [ { } ] [ "" ] }
{ [ 1array ] [ ] }
{ [ 2array ] [ " and " glue ] }
[ unclip swap (quibble) ", " glue ]
} switch ;
: quibble ( seq -- str ) (quibble) "{%s}" sprintf ;
{ } qw{ ABC } qw{ ABC DEF } qw{ ABC DEF G H }
[ quibble print ] 4 napply