Meikaku · 明確

Have your code make clear, and unambiguous promises. Find out when it breaks them.

Meikaku is a compiled programming language where the assumptions in your code are written as contracts, checked while the program runs, and pinned on whoever broke them. Meikaku's syntax was inspired by Eiffel, and matches most of the semantics. In most cases, Meikaku text is valid Eiffel text, except where noted. It's an homage to Eiffel, but built for low friction installation, setup, and use.

Meikaku means clear, unambiguous, explicit.

account.mei
note
    description: "A bank account that can never go negative."
    author: "asanaSoft"

class ACCOUNT
create
    make
feature
    balance: INT

    make(initial: INT) is
        require
            not_negative: initial >= 0
        do
            balance := initial
        end

    withdraw(amount: INT) is
        require
            positive: amount > 0
            covered: amount <= balance
        do
            balance := balance - amount
        ensure
            debited: balance = old balance - amount
        end
invariant
    never_negative: balance >= 0
end

class APPLICATION
create
    make
feature
    make is
        local
            acc: ACCOUNT
        do
            create acc.make(100)
            acc.withdraw(30)
            std_print("Balance: ".concat(acc.balance.to_string).concat("\n"))
            acc.withdraw(500)
        end
end
What mkc 1.2.0 printed
Balance: 70
panic: Contract violation: class 'ACCOUNT', feature 'withdraw', tag 'covered' [client blame]

Contracts

Three kinds of promise, each with a name on it

Every promise you write gets a tag, like covered above. When one is broken, the failure tells you the class, the routine, the tag, and which side broke the deal. There is nothing to decode. Contracts may look like other languages' asserts, but they are enforced across polymorphism and inheritance.

Before

What a routine needs

A precondition (require) is the caller’s side of the deal. If it fails, the caller is at fault, and the routine never runs.

client blame

After

What it promises

A postcondition (ensure) says what is true when the routine finishes, and old lets it compare against the state before. If it fails, the routine is at fault.

supplier blame

Always

What must stay true

A class invariant holds for the object’s whole life. It is checked after every call, and right after creation, so an object can’t start out broken.

supplier blame

For people and AI assistants

Intent you can check, not just read

A comment can drift out of date without anyone noticing. A contract can’t: it runs. When a teammate, or an AI assistant, changes a routine, the contract says what the routine still has to satisfy, and the first broken promise is reported by name. This narrows, or eliminates, the

  • Contracts are checked code. They are written in the same language as the program and evaluated while it runs. However, they are not simple asserts, like in other languages.
  • Intent has a place to live. A note clause at the top of a class says in plain words what it is for.
  • No compiler guessing. If two classes could be meant, or inherited features clash, it stops and asks you to say which. There is no silent resolution.
  • One way to write things. Assignment is :=, equality is =, and there is one way to write loops.

Then it becomes native code

Readable Zig, compiled natively

The compiler, mkc, translates Meikaku to Zig and the Zig toolchain builds the native program. You get a native executable, and Zig source you can read.

  • Contracts are your choice at build time. Build with -A none and every check is removed. A correct program behaves the same either way, because contracts must not change what a program does.
  • Memory is handled for you by the Boehm garbage collector, which ships with the compiler.
  • Zig is within reach. A routine can carry a native block of Zig, still wrapped in its contract.
  • A standard library for real work: collections, JSON, HTTP client and server, TLS, SQLite, and a client for AsanagiDB. See the library list.

Built with Meikaku

What we have actually built with it

Watchtower

Our uptime monitor. It probes 17 endpoints every two minutes and alerts when one fails. It ran beside the original Go version for 16 days and reported the same probe results, and it now runs on a Raspberry Pi 4 with 4 GB of memory.

A native desktop toolkit

Meikaku includes bindings to the libui-ng toolkit, so one program can open native windows on macOS and Linux. We built a demo graph explorer on it that reads from AsanagiDB. Clone the repo at https://git.asanasoft.com/asanaSoft/meikaku-explorer

AsanagiDB-TUI

Our TUI graph tool is written entirely in Maikaku, using the meikaku-tui library.

Meikaku and Asanagi

You never need to learn Meikaku to use AsanagiDB

AsanagiDB is written in Zig, and you talk to it with ordinary Gremlin clients. Meikaku is the language we choose for our own tools and services around it. If you only want the database, you can ignore Meikaku completely. If you like it, there is a Meikaku client for AsanagiDB in the standard library.

Explore the Asanagi products →

Where Meikaku is today

Young, and honest about it

Version 1.2.0 · MIT

Openly licensed under the MIT license. 1.2.0 introduces packages and a uses list inmeikaku.json: a project names the standard library groups, native drivers and libraries it needs, and anything unlisted is not found. This is a breaking change (seePackages and uses). The compiler now exits with an error code when a build fails, and a class of your own can take the place of a library class of the same name.

macOS and Linux

Packages target macOS on Apple silicon (signed and notarized) and Linux on x86_64 and ARM64 (aarch64). Requires Zig 0.16 on PATH (Homebrew installs it automatically; native-window apps on Linux also need GTK 3 and pkg-config). No Intel Mac or Windows package yet.

Still changing

Version 1.0 changed the syntax to match Eiffel, and the old forms are now rejected. Expect more refinement before it settles.

Install Meikaku 1.2.0

On macOS (Apple silicon), Homebrew installs Meikaku and [email protected] together:

brew tap asanagi/tap https://git.asanasoft.com/asanagi/homebrew-tap.git
brew install asanagi/tap/meikaku

Or download a release archive (requires Zig 0.16 on PATH):macOS Apple silicon (6.1 MB) ·Linux x86_64 (8.6 MB) ·Linux ARM64 (8.7 MB)