hoc, an acronym for High Order Calculator, is an
interpreted programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
that was used in the 1984 book
The Unix Programming Environment to demonstrate how to build interpreters using
Yacc
Yacc (Yet Another Compiler-Compiler) is a computer program for the Unix operating system developed by Stephen C. Johnson. It is a lookahead left-to-right rightmost derivation (LALR) parser generator, generating a LALR parser (the part of a co ...
.
hoc was developed by
Brian Kernighan
Brian Wilson Kernighan (; born January 30, 1942) is a Canadian computer scientist.
He worked at Bell Labs and contributed to the development of Unix alongside Unix creators Ken Thompson and Dennis Ritchie. Kernighan's name became widely known ...
and
Rob Pike
Robert Pike (born 1956) is a Canadian programmer and author.
He is best known for his work on the Go programming language while working at Google
and the Plan 9 operating system while working at Bell Labs, where he was a member of the Unix t ...
as a glorified interactive calculator. Its basic functionality is to evaluate floating-point numerical expressions, e.g., . 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
Research Unix refers to the early versions of the Unix operating system for DEC PDP-7, PDP-11, VAX and Interdata 7/32 and 8/32 computers, developed in the Bell Labs Computing Sciences Research Center (CSRC). The term ''Research Unix'' first app ...
in 1985, but it has not been generally adopted by commercial
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
systems or by
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
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
Free software, libre software, libreware sometimes known as freedom-respecting software is computer software distributed open-source license, under terms that allow users to run the software for any purpose as well as to study, change, distribut ...
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; text represents hoc's output:
1+2*3
7
angle=PI/3
r=sin(angle)
r
0.866025
r*2
1.73205
And a simple example of functions and flow control:
func atan2()
atan2(2,3)
0.982794
atan2(0,0)
atan2 domain error
0.0
References
*
External links
*
hoc implementations and versions
* AT&T versions:
*
The original code from the Unix Programming Environment book including hoc.
*
Source code of hocfrom Bell Labs, released as
free software
Free software, libre software, libreware sometimes known as freedom-respecting software is computer software distributed open-source license, under terms that allow users to run the software for any purpose as well as to study, change, distribut ...
. This is the Research Unix version, slightly improved over the one in the book.
*
Plan9 version of hocreleased under the
MIT License
The MIT License is a permissive software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts very few restrictions on reuse and therefore has high license compatibility.
Unl ...
. 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'
hoc manual
* Other versions:
*
an extended version of hocby Nelson H. F. Beebe.
*
an extended version of hocby Nadav Y. Har'El.
*
an extended version of hocby Jack Dennon.
*
by Michael Hines, John W. Moore, and Ted Carnevale.
{{Plan 9 commands
Software calculators
Free mathematics software
Numerical programming languages
Unix programming tools
Plan 9 commands