Hoc (programming language)

Last updated
hoc
Original author(s) Brian Kernighan, Rob Pike
(AT&T Bell Laboratories)
Initial release1984;39 years ago (1984)
Repository
Written in C
Operating system Unix, Plan 9
Platform Cross-platform
Type Programming language, Command
License Plan 9: MIT License

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.

Contents

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:

1+2*37 angle=PI/3  r=sin(angle)  r 0.866025 r*21.73205

And a simple example of functions and flow control:

 func atan2(){if($1>0){return atan($2/$1)}elseif($1<0){return atan($2/$1)+PI          }elseif($2>0){return PI/2}elseif($2<0){return-PI/2}else{print"atan2 domain error"return0}}    atan2(2,3)0.982794 atan2(0,0) atan2 domain error 0.0

Related Research Articles

<span class="mw-page-title-main">AWK</span> Programming language

AWK is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems.

<span class="mw-page-title-main">Brian Kernighan</span> Canadian computer scientist, co-creator of the Unix operating system

Brian Wilson Kernighan is a Canadian computer scientist.

C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems, device drivers, protocol stacks, though decreasingly for application software. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.

<span class="mw-page-title-main">Dennis Ritchie</span> American computer scientist, co-creator of the Unix operating system

Dennis MacAlistair Ritchie was an American computer scientist. He is most well known for creating the C programming language and, with long-time colleague Ken Thompson, the Unix operating system and B programming language. Ritchie and Thompson were awarded the Turing Award from the ACM in 1983, the Hamming Medal from the IEEE in 1990 and the National Medal of Technology from President Bill Clinton in 1999. Ritchie was the head of Lucent Technologies System Software Research Department when he retired in 2007. He was the "R" in K&R C, and commonly known by his username dmr.

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named after French mathematician, philosopher and physicist Blaise Pascal.

troff, short for "typesetter roff", is the major component of a document processing system developed by Bell Labs for the Unix operating system. troff and the related nroff were both developed from the original roff.

Yacc is a computer program for the Unix operating system developed by Stephen C. Johnson. It is a Look Ahead Left-to-Right Rightmost Derivation (LALR) parser generator, generating a LALR parser based on a formal grammar, written in a notation similar to Backus–Naur Form (BNF). Yacc is supplied as a standard utility on BSD and AT&T Unix. GNU-based Linux distributions include Bison, a forward-compatible Yacc replacement.

<span class="mw-page-title-main">Bourne shell</span> Command-line interpreter for operating systems

The Bourne shell (sh) is a shell command-line interpreter for computer operating systems.

Joseph Frank Ossanna, Jr. was an electrical engineer and computer programmer who worked as a member of the technical staff at the Bell Telephone Laboratories in Murray Hill, New Jersey. He became actively engaged in the software design of Multics, a general-purpose operating system used at Bell.

<span class="mw-page-title-main">GNU Units</span>

GNU Units is a cross-platform computer program for conversion of units of quantities. It has a database of measurement units, including esoteric and historical units. This for instance allows conversion of velocities specified in furlongs per fortnight, and pressures specified in tons per acre. Output units are checked for consistency with the input, allowing verification of conversion of complex expressions.

<span class="mw-page-title-main">Unix philosophy</span> Software development philosophy

The Unix philosophy, originated by Ken Thompson, is a set of cultural norms and philosophical approaches to minimalist, modular software development. It is based on the experience of leading developers of the Unix operating system. Early Unix developers were important in bringing the concepts of modularity and reusability into software engineering practice, spawning a "software tools" movement. Over time, the leading developers of Unix established a set of cultural norms for developing software; these norms became as important and influential as the technology of Unix itself, and have been termed the "Unix philosophy."

The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header <stdio.h>. The functionality descends from a "portable I/O package" written by Mike Lesk at Bell Labs in the early 1970s, and officially became part of the Unix operating system in Version 7.

<span class="mw-page-title-main">Sam (text editor)</span> Multi-file text editor

Sam is a multi-file text editor based on structural regular expressions. It was originally designed in the early 1980s at Bell Labs by Rob Pike with the help of Ken Thompson and other Unix developers for the Blit windowing terminal running on Unix; it was later ported to other systems. Sam follows a classical modular Unix aesthetic. It is internally simple, its power leveraged by the composability of a small command language and extensibility through shell integration.

bc, for basic calculator, is "an arbitrary-precision calculator language" with syntax similar to the C programming language. bc is typically used as either a mathematical scripting language or as an interactive mathematical shell.

Part of the troff suite of Unix document layout tools, eqn is a preprocessor that formats equations for printing. A similar program, neqn, accepted the same input as eqn, but produced output tuned to look better in nroff. The eqn program was created in 1974 by Brian Kernighan and Lorinda Cherry. It was implemented using yacc compiler-compiler.

<i>The Unix Programming Environment</i>

The Unix Programming Environment, first published in 1984 by Prentice Hall, is a book written by Brian W. Kernighan and Rob Pike, both of Bell Labs and considered an important and early document of the Unix operating system.

atan2 Arctangent function with two arguments

In computing and mathematics, the function atan2 is the 2-argument arctangent. By definition, is the angle measure between the positive -axis and the ray from the origin to the point in the Cartesian plane. Equivalently, is the argument of the complex number

<span class="mw-page-title-main">Unix</span> Family of computer operating systems

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, and others.

<span class="mw-page-title-main">Snellius–Pothenot problem</span>

The Snellius–Pothenot problem is a problem in planar surveying. Given three known points A, B and C, an observer at an unknown point P observes that the segment AC subtends an angle and the segment CB subtends an angle ; the problem is to determine the position of the point P..

References

hoc implementations and versions