Hoc (programming language)

hoc, an acronym for High Order Calculator, is an interpreted programming language that was used in the 1984 book The Unix Programming Environment to demonstrate how to build interpreters using Yacc.

hoc was developed by Brian Kernighan and Rob Pike as a glorified interactive calculator. Its basic functionality is to evaluate floating-point numerical expressions, e.g., 1+2*sin(0.7). Then, variables were added, conditionals, loops, user-defined functions, simple IO, and more, using a syntax resembling C.

An improved hoc interpreter was included in Eighth Edition Research Unix in 1985, but it has not been generally adopted by commercial Unix systems or by Linux distributions. Instead, the earlier calculator languages dc and bc have become widespread on those systems. hoc survived and continued to evolve as part of the Plan 9 operating system. Several improved versions of Hoc were released as free software by Bell Labs and other individuals (see list below). hoc is used, alongside python, as a scripting language for the Neuron simulator.

Examples
The following is a simple example of an interactive calculator session in hoc; highlighted text represents hoc's output: And a simple example of functions and flow control:

hoc implementations and versions

 * AT&T versions:
 * The original code from the Unix Programming Environment book, including hoc.
 * Source code of hoc from Bell Labs, released as free software. This is the Research Unix version, slightly improved over the one in the book.
 * Plan9 version of hoc released under the Lucent Public License. This version is slightly different from the Research Unix version, with the most notable difference being that numbered function arguments ($1, $2, etc., as in the Unix shell) were replaced by named arguments (as in C). See also Plan 9's hoc manual.
 * Other versions:
 * an extended version of hoc by Nelson H. F. Beebe.
 * an extended version of hoc by Nadav Y. Har'El.
 * an extended version of hoc by Jack Dennon.
 * an extended version of hoc by Michael Hines, John W. Moore, and Ted Carnevale.