Comma quibbling: Difference between revisions

→‎{{header|dc}}: Add implementation.
(→‎{{header|Commodore BASIC}}: Add implementation)
(→‎{{header|dc}}: Add implementation.)
Line 1,457:
{{out}}
<pre>["{}", "{ABC}", "{ABC and DEF}", "{ABC, DEF, G and H}"]</pre>
 
=={{header|dc}}==
<syntaxhighlight lang="dc">[main entry point: print brackets, call o if stack not empty]sx
[ [{]n z 0 !=o [}]pR ]sq
 
[nonempty stack: if more than 1 item, call t. then print top of stack.]sx
[ z 1 !=t n ]so
 
[more than 1 item. reverse (flip) stack into r register, call p to print
most of it, then pop the last item back from r so it's there to be printed
after we return]sx
[ lfx lpx Lr ]st
 
[utility routine: reverse (flip) the stack into the r register]sx
[ Sr z 0 !=f ]sf
 
[main print routine. get next item from stack in r register,
print it. If there are more than 2 items left, print a comma (c). Otherwise,
if there are exactly two items left, print " and " (a). Finally, if there
are more than 2 items left, recurse.]sx
[ Lr n 2 yr >c 2 yr =a 2 yr >p]sp
 
[utility routine: print a comma followed by a space]sx
[ [, ]n ]sc
 
[utility routine: print a " and "]sx
[ [ and ]n ]sa
 
[run tests]sx
lqx
[ABC] lqx
[ABC] [DEF] lqx
[ABC] [DEF] [G] [H] lqx
</syntaxhighlight>
 
{{out}}
<pre>{}
{ABC}
{ABC and DEF}
{ABC, DEF, G and H}</pre>
 
=={{header|DCL}}==
Line 1,501 ⟶ 1,541:
{ABC and DEF}
{ABC, DEF, G and H}</pre>
 
=={{header|Delphi}}==
See [[#Pascal|Pascal]].
1,480

edits