Comma quibbling: Difference between revisions

→‎Tcl: Added implementation
m (→‎{{header|Rexx}}: fix spelling of header)
(→‎Tcl: Added implementation)
Line 192:
=={{header|Rust}}==
{{incomplete|Rust|output for no input words missing.}}
<lang Rust>fn quibble(seq: &[~str]) -> ~str {
fn quibble(seq: &[~str]) -> ~str {
match seq {
[] => ~"{}",
Line 205 ⟶ 204:
println(quibble([~"ABC", ~"DEF"]));
println(quibble([~"ABC", ~"DEF", ~"G", ~"H"]));
}</lang>
{{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 ", "]\}
}
</lang>
 
foreach input { {} {"ABC"} {"ABC" "DEF"} {"ABC" "DEF" "G" "H"} } {
puts [commaQuibble $input]
}</lang>
{{out}}
<pre>
{}
{ABC}
{ABC and DEF}
{ABC, DEF, G and H}</pre>
</pre>
Anonymous user