plan9port/man/man1/hoc.html
2005-01-14 03:45:44 +00:00

136 lines
6 KiB
HTML

<head>
<title>hoc(1) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>HOC(1)</b><td align=right><b>HOC(1)</b>
<tr><td width=20><td colspan=2>
<br>
<p><font size=+1><b>NAME </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
hoc &ndash; interactive floating point language<br>
</table>
<p><font size=+1><b>SYNOPSIS </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>hoc</font></tt> [ <i>file ...</i> ] [ <tt><font size=+1>&#8722;e</font></tt> <i>expression</i> ]<br>
</table>
<p><font size=+1><b>DESCRIPTION </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<i>Hoc</i> interprets a simple language for floating point arithmetic,
at about the level of BASIC, with C-like syntax and functions.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
The named <i>files</i> are read and interpreted in order. If no <i>file</i>
is given or if <i>file</i> is <tt><font size=+1>&#8722;</font></tt> <i>hoc</i> interprets the standard input. The
<tt><font size=+1>&#8722;e</font></tt> option allows input to <i>hoc</i> to be specified on the command line,
to be treated as if it appeared in a file.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Hoc</i> input consists of <i>expressions</i> and <i>statements</i>. Expressions
are evaluated and their results printed. Statements, typically
assignments and function or procedure definitions, produce no
output unless they explicitly call <i>print</i>.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
Variable names have the usual syntax, including <tt><font size=+1>_</font></tt>; the name <tt><font size=+1>_</font></tt>
by itself contains the value of the last expression evaluated.
The variables <tt><font size=+1>E</font></tt>, <tt><font size=+1>PI</font></tt>, <tt><font size=+1>PHI</font></tt>, <tt><font size=+1>GAMMA</font></tt> and <tt><font size=+1>DEG</font></tt> are predefined; the last
is 59.25..., degrees per radian.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
Expressions are formed with these C-like operators, listed by
decreasing precedence.<br>
<tt><font size=+1>^</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exponentiation<br>
<tt><font size=+1>! &#8722; ++ &#8722;&#8722;<br>
* / %<br>
+ &#8722;<br>
&gt; &gt;= &lt; &lt;= == !=<br>
&amp;&amp;<br>
||<br>
= += &#8722;= *= /= %=<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
Built in functions are <tt><font size=+1>abs</font></tt>, <tt><font size=+1>acos</font></tt>, <tt><font size=+1>asin</font></tt>, <tt><font size=+1>atan</font></tt> (one argument), <tt><font size=+1>cos</font></tt>,
<tt><font size=+1>cosh</font></tt>, <tt><font size=+1>exp</font></tt>, <tt><font size=+1>int</font></tt>, <tt><font size=+1>log</font></tt>, <tt><font size=+1>log10</font></tt>, <tt><font size=+1>sin</font></tt>, <tt><font size=+1>sinh</font></tt>, <tt><font size=+1>sqrt</font></tt>, <tt><font size=+1>tan</font></tt>, and <tt><font size=+1>tanh</font></tt>. The
function <tt><font size=+1>read(x)</font></tt> reads a value into the variable <tt><font size=+1>x</font></tt> and returns
0 at EOF; the statement <tt><font size=+1>print</font></tt> prints a list of expressions that
may include string constants such as
<tt><font size=+1>&quot;hello\n&quot;</font></tt>.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<tt><font size=+1>
</font></tt>Control flow statements are <tt><font size=+1>if</font></tt>-<tt><font size=+1>else</font></tt>, <tt><font size=+1>while</font></tt>, and <tt><font size=+1>for</font></tt>, with braces
for grouping. Newline ends a statement. Backslash-newline is equivalent
to a space.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
Functions and procedures are introduced by the words <tt><font size=+1>func</font></tt> and
<tt><font size=+1>proc</font></tt>; <tt><font size=+1>return</font></tt> is used to return with a value from a function.<br>
</table>
<p><font size=+1><b>EXAMPLES </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>func gcd(a, b) {<br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
temp = abs(a) % abs(b)<br>
if(temp == 0) return abs(b)<br>
return gcd(b, temp)<br>
</table>
}<br>
for(i=1; i&lt;12; i++) print gcd(i,12)<br>
</font></tt>
</table>
<p><font size=+1><b>SOURCE </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>/usr/local/plan9/src/cmd/hoc<br>
</font></tt>
</table>
<p><font size=+1><b>SEE ALSO </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<a href="../man1/bc.html"><i>bc</i>(1)</a>, <a href="../man1/dc.html"><i>dc</i>(1)</a><br>
B. W. Kernighan and R. Pike, <i>The Unix Programming Environment,</i>
Prentice-Hall, 1984<br>
</table>
<p><font size=+1><b>BUGS </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
Error recovery is imperfect within function and procedure definitions.<br>
</table>
<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>