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

15 lines
345 B
Factor
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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