Comma quibbling: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) m →{{header|Rexx}}: fix spelling of header |
→Tcl: Added implementation |
||
Line 192: | Line 192: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
{{incomplete|Rust|output for no input words missing.}} |
{{incomplete|Rust|output for no input words missing.}} |
||
<lang Rust> |
<lang Rust>fn quibble(seq: &[~str]) -> ~str { |
||
fn quibble(seq: &[~str]) -> ~str { |
|||
match seq { |
match seq { |
||
[] => ~"{}", |
[] => ~"{}", |
||
Line 205: | Line 204: | ||
println(quibble([~"ABC", ~"DEF"])); |
println(quibble([~"ABC", ~"DEF"])); |
||
println(quibble([~"ABC", ~"DEF", ~"G", ~"H"])); |
println(quibble([~"ABC", ~"DEF", ~"G", ~"H"])); |
||
⚫ | |||
{{out}} |
|||
<pre> |
|||
{ABC} |
|||
{ABC and DEF} |
|||
{ABC, DEF, G and H} |
|||
</pre> |
|||
=={{header|Tcl}}== |
|||
<lang tcl>proc commaQuibble {lst} { |
|||
if {[llength $lst] > 1} { |
|||
set lst [lreplace $lst end-1 end [join [lrange $lst end-1 end] " and "]] |
|||
} |
|||
return \{[join $lst ", "]\} |
|||
} |
} |
||
⚫ | |||
foreach input { {} {"ABC"} {"ABC" "DEF"} {"ABC" "DEF" "G" "H"} } { |
|||
puts [commaQuibble $input] |
|||
}</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
{} |
|||
{ABC} |
{ABC} |
||
{ABC and DEF} |
{ABC and DEF} |
||
{ABC, DEF, G and H} |
{ABC, DEF, G and H} |
||
</pre> |