[TUHS] dc after bc.

Ralph Corderoy ralph at inputplus.co.uk
Thu Feb 17 00:34:45 AEST 2022


Dave Horsfall wrote:
> > I never quite got DC, and wondered at the duality of them.
> You know you're a greybeard if you can remember why the DC sequence
> "99k2vp8opq" was so popular...

I used to use bc, and still do when ‘a(1)*4’ would be useful, but moved
to dc because I didn't know it well and wanted to improve.  Plus reverse
Polish tends to better match what I want to enter.

But I think I'm missing the idiomatic way to use it; I'm puzzled there's
no command to print and pop the top of stack followed by a linefeed.

- ‘p’ prints the top of stack without popping it, and then linefeed.
- ‘n’ pops and prints the top of stack but without a linefeed.
- ‘f’ prints the stack, one number per line.
- ‘c’ clears the stack.

This means my multiple unrelated calculations tend to end with ‘pc’ as
otherwise the stack builds up and I might accidentally use old stuff on
the stack if the operators for this next sum don't push enough operands
of their own.

If I use n then the stack is popped, which I want, but the cursor
remains after the number.  I could see that's useful if the number was
still the top of stack because I could continue typing on the same line
to make use of it.

So I'm left with ‘pc’ or ‘fc’, or ‘n10P’.  Popping without printing is
‘ss’ or similar to store it in register s.  So ‘pss’ prints ToS and pops
just it, simpler than ‘n10P’.

How did dc's users balance printing the results with not building stack

Cheers, Ralph.

More information about the TUHS mailing list