NYH HOC

More than just a calculator

What is hoc?

Hoc, the High Order Calculator, is an interpreted language for floating-point calculations. Its most basic use is as a powerful and convenient calculator, interactively evaluating expressions such as 1+2*sin(0.7). But hoc is no ordinary calculator: It also lets you assign values to variables, define your own functions, and use loops, conditionals, and everything else you'd expect in a programming language.

Hoc was developed by Brian Kernighan and Rob Pike, and introduced in their 1984 book The Unix Programming Environment. In the book, hoc was used as an example of how to develop an interpreter from scratch, using Yacc. But hoc was more than an example — it was a genuinely useful tool, more convenient for everyday calculations than contemporary calculator utilities (like bc) or later graphical calculators (like xcalc). Slightly improved versions of hoc lived on in AT&T's Research Unix, and later their Plan 9 operating system, but unfortunately never became mainstream, and was never included in commercial versions of Unix or by Linux distributions.

Since 1995, hoc is free software (see the Research Unix version and the Plan 9 version).

What is NYH hoc?

At the same time, some of the book's readers actually took the time to type in the hoc source code from the book, and started using it. A few of those were intrigued by hoc, and by Yacc (the tool used to write its parser) and started improving on hoc. A few of these improved versions have been released in the two decades after the book's publication, and some of them are mentioned in Hoc's Wikipedia entry.

One of these improved versions is this one. It was written by Nadav Y. Har'El, who slowly continued to evolve hoc between 1986 to 1997. This branch has more portable code (and works on the large number of machines and compilers types that appeared since 1984), and adds numerous new features, including local variables in functions, real for loops and short-circuit boolean operators, and much more.

See this README file for the complete list of this hoc's improvements over the book version.

How to get it

This version of hoc is released as free software, using a BSD-like license with attribution required, just like AT&T's 1995 release. See the LICENSE file (also included with the source) for more information.


By Nadav Har'El