HOC(1)

๐Ÿ“ฆ
version 0_git20260208 ยท 2 versions
, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

๐Ÿ’– 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 variable x, and returns 0 at EOF
  • print (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 ๐Ÿงš

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

๐Ÿ’€ 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 ๐Ÿซถ๐Ÿ’–โœจ