RosettaCodeData/Task/Comma-quibbling/Factor/comma-quibbling.factor

15 lines
345 B
Factor
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
USING: inverse qw sequences ;
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
: (quibble) ( seq -- seq' )
{
{ [ { } ] [ "" ] }
{ [ 1array ] [ ] }
{ [ 2array ] [ " and " glue ] }
[ unclip swap (quibble) ", " glue ]
} switch ;
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
: quibble ( seq -- str ) (quibble) "{%s}" sprintf ;
{ } qw{ ABC } qw{ ABC DEF } qw{ ABC DEF G H }
[ quibble print ] 4 napply