Calculon - a calculator for nerds

Update December 2014: This post is now somewhat outdated, please see the github repo for more up to date information.

Can’t sleep. Write blog post.

I used to spend a lot of time using a Python REPL as a calculator, copying and pasting values back and forth between the REPL and, cursing, hitting ctrl-a, typing hex(, hitting ctrl-e, and typing ). I thought “THERE’S GOT TO BE A BETTER WAY”. Now there is.

Calculon - A terminal-based programmer’s calculator endowed with unholy acting talent by the Robot Devil.

calculon example

Calculon is basically a curses window jammed on top of a Python REPL (bpython initially). Any code you type into the REPL will be executed as usual, with any numeric values displayed in the interface at the top in a variety of bases and formats. There are a couple of differences to the basic REPL:

  • If the code begins with an operator the line will be prepended with the last result, allowing the user to do something like this:

      >>> 1234
      >>> <<1
  • If the code is empty (ie. the user just hits enter), the last operation will be re-evaluated:

  • There are functions called watch() and unwatch() exposed, allowing the user to track variables in the main display (as per the screen capture above).

Calculon also supports configurable bit length and display width for the binary display, and left/right alignment:

calculon example2

Check it out on my github.

There are a few things that I (and my pal richo) plan to do to it in the near future:

  • Decouple the display window and REPL, allowing them to be executed in different terminals (ala Voltron)
  • Add support for other REPLs (e.g. IPython)
  • Add glue between Calculon and Voltron, allowing it to be used as a display for watching registers/memory