Hoc (programming language)
Encyclopedia
hoc, an acronym for High Order Calculator, is an interpreted
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...

 programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 that was used in the 1984 book The Unix Programming Environment
The Unix Programming Environment
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....

 to demonstrate how to build interpreters using Yacc
Yacc
The computer program yacc is a parser generator developed by Stephen C. Johnson at AT&T for the Unix operating system. The name is an acronym for "Yet Another Compiler Compiler." It generates a parser based on an analytic grammar written in a notation similar to BNF.Yacc used to be available as...

.

Hoc was developed by Brian Kernighan
Brian Kernighan
Brian Wilson Kernighan is a Canadian computer scientist who worked at Bell Labs alongside Unix creators Ken Thompson and Dennis Ritchie and contributed to the development of Unix. He is also coauthor of the AWK and AMPL programming languages. The 'K' of K&R C and the 'K' in AWK both stand for...

 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 Research Unix
Research Unix
Research Unix is a term used to refer to 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 Science Research Center ....

, but it has not been generally adopted by commercial Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 systems or by Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 distributions. Instead, the calculator languages dc
Dc (Unix)
dc is a cross-platform reverse-polish desk calculator which supports arbitrary-precision arithmetic. It is one of the oldest Unix utilities, predating even the invention of the C programming language; like other utilities of that vintage, it has a powerful set of features but an extremely terse...

 and bc
Bc programming language
bc, for bench 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....

 have become widespread on those systems. Hoc survived and continued to evolve as part of the Plan 9
Plan 9 from Bell Labs
Plan 9 from Bell Labs is a distributed operating system. It was developed primarily for research purposes as the successor to Unix by the Computing Sciences Research Center at Bell Labs between the mid-1980s and 2002...

 operating system. Several improved versions of Hoc were released as free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 by Bell Labs and other individuals (see list below).

Examples

The following is a simple example of an interactive calculator session in Hoc; bold 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{
if($1>0){
return atan($2/$1)
} else if ($1<0){
return atan($2/$1)+PI
} else if ($2>0){
return PI/2
} else if ($2<0){
return -PI/2
} else {
print "atan2 domain error"
return 0
}
}

atan2(2,3)
0.982794
atan2(0,0)
atan2 domain error
0.0

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
      Free software
      Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

      . This is the Research Unix version, slightly improved over the one in the book.
    • Plan9 version of Hoc released under the Lucent Public License
      Lucent Public License
      The Lucent Public License is an open-source license created by Lucent Technologies. It has been released in two versions: Version 1.0 and 1.02....

      . 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:
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK