Comma quibbling: Difference between revisions

m
→‎{{header|dc}}: Better register names and comments.
(→‎{{header|dc}}: Add implementation.)
m (→‎{{header|dc}}: Better register names and comments.)
Line 1,459:
 
=={{header|dc}}==
<syntaxhighlight lang="dc">[(q)uibble: main entry point:. print brackets, callcalling on in between if stack not empty]sx
empty.]sx
[ [{]n z 0 !=on [}]pR ]sq
 
[nonempty stack(n)onempty: if more than 1 item, call tm. then print top of stack.]sx
[ z 1 !=tm n ]sosn
 
[more(m)ore: thancall 1f item.to reverse (flip) stack into r register, call p to print most of it,
most of it, then pop the last item back fromonto the main rstack so it's there to be printed
after we return]sx
[ lfx lpx Lr ]stsm
 
[(f)lip: utility routine: reverseto (flip)reverse the stack into the r register]sx
[ Sr z 0 !=f ]sf
 
[main print routine.(p)rint: get next item from stack in r register, and print it. If there are
print it. If there are more than 2 items left, print a comma (c) and recurse. Otherwise,If there are exactly
if there are exactly two items left, print " and " (a). Finally,and if therereturn.]sx
are more than 2 items left, recurse.]sx
[ Lr n 2 yr >c 2 yr =a 2 yr >p]sp
 
[(c)omma: utility routine: to print a comma followed by a space]sx
[ [, ]n ]sc
 
[(a)and: utility routine: printto a print " and "]sx
[ [ and ]n ]sa
 
[run tests]sx
lqx
[ABC] lqx
[ABC] [DEF] lqx
[ABC] [DEF] [G] [H] lqx</syntaxhighlight>
</syntaxhighlight>
 
{{out}}
1,481

edits