Hacker News new | past | comments | ask | show | jobs | submit login

I just did `man dc` and then tried it out to run 1 + 2. I tried only entering the numbers, then tried writing "push 1", then guessed, that maybe it is just "p 1" and then guessed, that I also need to "p +" and hit "=" and return. Voila! Figured it out intuitively! Great!



It's still one of the quickest ways to do math on the command line.

dc -e '3 k 57 47 / p'

Or what have you.

It's pretty useful. I recommend spending an hour or two with it. You'll use it.

One of the nice things about rpn is if you forget something or want to modify things, you'll quickly find out that it's more convenient.

A little syntax weirdness apparently goes a long way in making things ridiculously easier to manipulate.

You can write programs with it btw. Hobby away: https://rosettacode.org/wiki/Category:Dc

Things get delightfully cryptic: https://rosettacode.org/wiki/Generate_lower_case_ASCII_alpha...

Go through a Forth tutorial to get the hang of RPN style programming if that's truly gibberish to you. It won't make it easy, but it will make it readable


Haven't used a language with RPN as default, but Forth is somewhere on my endless "to look at at some point" list : )


Unless there's a difference between yours and mine `dc` that's not quite right:

   10 # pushes 10
   20 # pushes 20
   +  # pops 20 10 sums, pushes results
   p  # prints top of stack (peek)
Equal (`=`) is a conditonal macro invocation `=r`: pops two values off stack, invokes (the contents of register) `r` if they are equal.

  [p]sa # store peek stack top as macro in a
  1337
  10
  20
  +
  30
  =a # Stack should be 1337, 30 (20+10) and 30, so should output 1337
     # pops 30 and 30; 30==30;p -> top is 1337




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: