Unix/Linux Go Back    

Plan 9 - man page for hoc (plan9 section 1)

Linux & Unix Commands - Search Man Pages
Man Page or Keyword Search:   man
Select Man Page Set:       apropos Keyword Search (sections above)

HOC(1)											   HOC(1)

       hoc - interactive floating point language

       hoc [ file ...  ]

       Hoc  interprets	a  simple  language  for floating point arithmetic, at about the level of
       BASIC, with C-like syntax and functions.

       The named files are read and interpreted in order.  If no file is given or if file is  hoc
       interprets the standard input.

       Hoc  input  consists  of  expressions and statements.  Expressions are evaluated and their
       results printed.  Statements, typically assignments and function or procedure definitions,
       produce no output unless they explicitly call print.

       Variable  names	have the usual syntax, including the name by itself contains the value of
       the last expression evaluated.  The variables E, PI, PHI, GAMMA and  DEG  are  predefined;
       the last is 59.25..., degrees per radian.

       Expressions are formed with these C-like operators, listed by decreasing precedence.

       ^      exponentiation

       ! - ++ --

       * / %

       + -

       > >= < <= == !=



       = += -= *= /= %=

       Built  in  functions  are  abs, acos, asin, atan (one argument), cos, cosh, exp, int, log,
       log10, sin, sinh, sqrt, tan, and tanh.  The function read(x) reads a value into the  vari-
       able  x	and  returns  0 at EOF; the statement print prints a list of expressions that may
       include string constants such as "hello\n".

       Control flow statements are if-else, while, and for, with braces  for  grouping.   Newline
       ends a statement.  Backslash-newline is equivalent to a space.

       Functions  and  procedures  are	introduced  by the words func and proc; return is used to
       return with a value from a function.   Within  a  function  or  procedure,  arguments  are
       referred to as $1, $2, etc.; all other variables are global.

       func gcd() {
	    temp = abs($1) % abs($2)
	    if(temp == 0) return abs($2)
	    return gcd($2, temp)
       for(i=1; i<12; i++) print gcd(i,12)


       bc(1), dc(1)
       B. W. Kernighan and R. Pike, The Unix Programming Environment, Prentice-Hall, 1984

       Error recovery is imperfect within function and procedure definitions.

Unix & Linux Commands & Man Pages : ©2000 - 2018 Unix and Linux Forums

All times are GMT -4. The time now is 07:20 PM.