Show HN: The Oct Programming Language for scientific programming

Posted by YuechenLi 11 hours ago

Counter3Comment0OpenOriginal

Apologies in advance if my writing is unclear.

First, why make another programming language? This came out of my general frustration with working with MATLAB and Python during grad school as well as at work. I'm a mechanical engineer; I write Python scripts for my own use semi-regularly. My issue with Python is that while writing easy, debugging Python code I wrote is hard once the code gets big. Sharing my Python code to colleagues is very difficult as most of them are less technical on coding than I am, so asking them to setup a full Python env just to run a script is out of the question.

Then, the Two-Language Problem for scientific computing: write the prototype code in Python/MATLAB and rewrite the performance sensitive code in C++/Rust when needed. The problem is that C++ and Rust are not very easy to learn and converting from a dynamically typed language like Python to a strict, statically typed language like Rust is not easy, especially for people who are not software engineers.

The name Oct is a reference to GNU Octave and started as my concept of what Octave should have been, and the name stuck. About 75k lines of Oct code are in the repo across experiments, libraries, and examples. Pretty much all of it is written by Claude/Codex, my role is only to prevent drift/hallucinations.

Features, in no particular order:

- Function first, statically typed, both interpreted and compiled: Oct code compiles to a Go binary via MIR codegen, runs on anything that Go runs at Go speed, and inherits Go's absurd compile speed, which means that a JIT is mostly unnecessary. - The entire Go ecosystem is available for Oct if you write a wrapper around it: Oct's `IO.Xlsx` library is `excelize`, Oct's builtin plot is `gonum/plot`, Oct's benchmark profiling is pprof, Oct's C interop is CGo. - Boring syntax, easy to learn. If you know Rust/Go/C#/Swift, learning Oct would take a few hours at most. Vice versa, if you learn Oct, then you are halfway to knowing how to write Rust already; - Octest, xUnit.NET style testing framework with `[Fact]/[Theory]` and various Asserts. - Foundational SI unit built into the language and enforced by typechecker: you can't add Int<m> and Int<kg> together. Units also propagate. ```oct fn StiffnessForce(K: Matrix<Float<kg/s^2>>, u: Vector<Float<m>>) -> Vector<Float<kgm/s^2>> { return K @ u // Matrix<Float<kg/s^2>> @ Vector<Float<m>> → Vector<Float<kgm/s^2>> } ``` - You can't ignore errors, Oct is exception free and `null`/`nil`-free, all errors must be handled explicitly: `?` for propagation, `!` for unwrap, or fallible `match`. - Arrays and vector/matrix are separate but related concepts, with vectors/matrices explicitly defined as Rank 1 and 2 tensors, and Einstein notation for tensors is built into the language. ```oct let c = a[i, k] * b[k, j] ``` - Octomata, Oct's own built in control system runtime, using explicit finite state machines and utility scoring as primitives for control systems.

```oct package Main

flow DoorControl(openCmd: Bool, closeCmd: Bool, blocked: Bool) -> String { state Closed { when { case openCmd and blocked == false -> goto Opening else -> return "closed" } }

    state Opening {
        when {
            case blocked -> goto Closed
            case closeCmd -> goto Closing
            else -> return "opening"
        }
    }

    state Closing { return "closing" }
} ``` Oct is very much a work in progress, but enough jank/bugs has been fixed that hopefully it wouldn't be embarrassing to show it off now, although rough edges still expected. So, would love some feedback.

Comments

Comment by jfy0420 6 hours ago

[flagged]