Share to: share facebook share twitter share wa share telegram print page

 

Hoc (programming language)

hoc
Original author(s)Brian Kernighan, Rob Pike
(AT&T Bell Laboratories)
Initial release1984; 41 years ago (1984)
Repository
Written inC
Operating systemUnix, Plan 9
PlatformCross-platform
TypeProgramming language, Command
LicensePlan 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.

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*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

References

  • Kernighan, Brian W.; Pike, Rob (1984). The Unix Programming Environment. Prentice Hall. ISBN 0-13-937681-X.

hoc implementations and versions

Kembali kehalaman sebelumnya


Index: pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve 
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9