Hoc (programming language)

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 Research Unix, but it has not been generally adopted by commercial Unix systems or by Linux distributions. Instead, the 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).

Examples

The following is a simple example of an interactive calculator session in Hoc; emboldened 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:
** [http://cm.bell-labs.com/who/bwk/unixprogenv.tar.gz The original code from the Unix Programming Environment book] , including hoc.
** [http://netlib.bell-labs.com/~bwk/hoc.sh 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.
** [http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/hoc/ 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 [http://plan9.bell-labs.com/magic/man2html/1/hoc hoc manual] .
* Other versions:
** [http://www.math.utah.edu/pub/hoc/ an extended version of Hoc] by Nelson H. F. Beebe.
** [http://nadav.harel.org.il/homepage/hoc/ an extended version of Hoc] by Nadav Y. Har'El.
** [http://www.linuxjournal.com/?q=article/5810 an extended version of Hoc] by Jack Dennon.
** [http://www.neuron.yale.edu/neuron/docs/refman/hoc.html an extended version of Hoc] by Michael Hines, John W. Moore, and Ted Carnevale.


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Bc programming language — bc is an arbitrary precision calculator language with syntax similar to the C programming language. It is generally used by typing the command bc on a Unix command prompt and entering a mathematical expression, such as (1 + 3) * 2 , whereupon 8… …   Wikipedia

  • Haskell (programming language) — Haskell Paradigm(s) functional, lazy/non strict, modular Appeared in 1990 Designed by Simon Peyton Jones, Lennart Aug …   Wikipedia

  • C (programming language) — C The C Programming Language[1] (aka K R ) is the seminal book on C …   Wikipedia

  • Lisp (programming language) — Infobox programming language name = Lisp paradigm = multi paradigm: functional, procedural, reflective generation = 3GL year = 1958 designer = John McCarthy developer = Steve Russell, Timothy P. Hart, and Mike Levin latest release version =… …   Wikipedia

  • Racket (programming language) — Racket Paradigm(s) Multi paradigm: Functional, Procedural, Modular, Object oriented, Reflective, Meta Appeared in 1994 Developer …   Wikipedia

  • Eiffel (programming language) — Infobox programming language name = Eiffel paradigm = object oriented year = 1986 designer = Bertrand Meyer developer = Bertrand Meyer Eiffel Software latest release version = 4.2 latest release date = Feb 6, 1998 typing = static typing, strong… …   Wikipedia

  • Indus programming language — Indus is an object oriented programming language for Ubiquitous computing. The primary components of the Indus platform are a programming language to implement software agents, libraries to provide services to agents on a distributed network, and …   Wikipedia

  • TRAC (programming language) — TRAC (for Text Reckoning And Compiling) is a programming language developed in the early 1960s by Calvin Mooers (1919 1994). It was one of three first languages recommended by Ted Nelson in Computer Lib .TRAC is a purely text based language a… …   Wikipedia

  • Hoc — may refer to: * Hellenic Olympic Committee, one of the oldest National Olympic Committees. * Hoc (Beowulf), a Danish King from Beowulf. * Hoc (programming language), a calculator and programming language. * Hypertrophic (Obstructive)… …   Wikipedia

  • language — /lang gwij/, n. 1. a body of words and the systems for their use common to a people who are of the same community or nation, the same geographical area, or the same cultural tradition: the two languages of Belgium; a Bantu language; the French… …   Universalium

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”