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"]));
}</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}}
{{out}}
<pre>
<pre>
{}
{ABC}
{ABC}
{ABC and DEF}
{ABC and DEF}
{ABC, DEF, G and H}</pre>
{ABC, DEF, G and H}
</pre>