Comma quibbling: Difference between revisions
Content deleted Content added
m →{{header|Factor}}: give the comma-quibble word fewer responsibilities |
→{{header|Factor}}: rewrite |
||
Line 1,224: | Line 1,224: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<lang factor>USING: |
<lang factor>USING: formatting generalizations qw ; |
||
IN: rosetta-code.comma-quibble |
|||
⚫ | |||
: wrap ( str -- str' ) "{" prepend "}" append ; |
|||
: quibble-pair ( seq -- str ) " and " join wrap ; |
|||
⚫ | |||
[ but-last ] [ last ] bi [ ", " join ] dip { } 2sequence |
|||
quibble-pair ; |
|||
: comma-quibble ( seq -- str ) |
|||
dup length { |
dup length { |
||
{ 0 [ drop " |
{ 0 [ drop "" ] } |
||
{ 1 [ first |
{ 1 [ first ] } |
||
{ 2 [ |
{ 2 [ first2 " and " glue ] } |
||
[ drop |
[ drop unclip-last [ ", " join ] dip " and " glue ] |
||
} case ; |
} case "{%s}" sprintf ; |
||
{ } qw{ ABC } qw{ ABC DEF } qw{ ABC DEF G H } |
{ } qw{ ABC } qw{ ABC DEF } qw{ ABC DEF G H } |
||
[ |
[ quibble print ] 4 napply</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |