HOC(1)
๐ hoc(1) โ like, the interactive floating point language bestie ๐
okay so picture this: hoc is a whole little language for doing floating point math, right? It's giving BASIC energy but with C-like syntax and functions. She's simple, she's cute, she slays at arithmetic. Let's get into it ๐
โจ SYNOPSIS โจ
hoc [ file ... ] [ -e expression ]
๐ธ DESCRIPTION ๐ธ
So hoc interprets a simple language for floating point arithmetic โ about the level of BASIC, but with C-like syntax and functions. Lowkey iconic.
The named files get read and interpreted in order. If no file is given, or if file is hoc... it just reads standard input, bestie. And the -e option lets you feed input to hoc straight on the command line, treated exactly as if it appeared in a file. Convenient โจ
hoc input is made of expressions and statements:
- Expressions get evaluated and their results printed ๐
- Statements โ typically assignments and function or procedure definitions โ produce no output unless they explicitly call
print. No cap.
Variable names have the usual syntax, and (this is the weird-but-true part) the name by itself contains the value of the last expression evaluated. The variables E, PI, PHI, GAMMA and DEG are predefined; DEG is 59.25..., degrees per radian ๐
๐งฎ the operators, listed by decreasing precedence
^โ exponentiation!,-,++,--*,/,%+,->,>=,<,<=,==,!=&&||=,+=,-=,*=,/=,%=
๐ฆ the built-in functions
abs, acos, asin, atan (one argument), cos, cosh, exp, int, log, log10, sin, sinh, sqrt, tan, and tanh. All of them, periodt.
Also:
read(x)โ reads a value into the variablex, and returns0at EOFprint(the statement) โ prints a list of expressions, and those expressions may include string constants such as"hello\n"
๐ control flow & definitions
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. Go off, recursive queen ๐
โญ EXAMPLES โญ
func gcd(a, b) {
temp = abs(a) % abs(b)
if(temp == 0) return abs(b)
return gcd(b, temp)
}
for(i=1; i<12; i++) print gcd(i,12)
like... she's computing greatest common divisors. main character energy fr fr ๐ฅ
๐ SOURCE ๐
/src/cmd/hoc
๐ง SEE ALSO ๐ง
๐ BUGS ๐
Error recovery is imperfect within function and procedure definitions. Not me warning you โ it's literally in the manual, bestie. Beware ๐
okay that's the whole thing!! this page lives in the General Commands Manual (that's the HOC(1) situation up top and down at the bottom ๐
) and ngl there's no date on this one, so consider this your cute little sign-off: go forth and do floating point math, you gorgeous nerd ๐ซถ๐โจ
๐ฆ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 ยท LPL-1.02
- arch rolling: plan9port 20261021-2 ยท custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms