Skip to content

Instantly share code, notes, and snippets.

View bobzhang's full-sized avatar
🎯
Focusing

Hongbo Zhang bobzhang

🎯
Focusing
View GitHub Profile
@bobzhang
bobzhang / moonbit-vs-rust-ai-agents.md
Created October 2, 2026 14:53
MoonBit vs Rust for AI coding agents: the same SQLite-compatible engine built 6 times by Claude Opus 5.5

MoonBit vs Rust for AI coding agents: same database engine, built 6 times

We had Claude Opus 5.5 (Claude Code, effort high) build the same SQLite-compatible SQL engine three times in Rust and three times in MoonBit: nine milestones per build, ending at about 13,000 lines, graded against 489 tests generated by SQLite 3.53 (half hidden from the agent).

Result: a young language with a fraction of Rust's training data reached parity on agent cost and quality, and wrote about 12% less code.

Per build (mean of 3) Rust MoonBit MoonBit ÷ Rust
Estimated agent cost $43.86 ± 13.25 $41.09 ± 3.97 0.94 (median 1.12)
Output tokens 868k 762k 0.88
@bobzhang
bobzhang / README.md
Created September 2, 2026 09:56
MoonBit vs Rust: bit-level patterns on bytes, u4be..u13be, u32le, v128le SIMD (vs shifts/masks/SWAR)

MoonBit vs Rust: bit-level patterns on bytes (incl. v128le)

MoonBit matches Bytes / BytesView at bit granularity. u4be(x) binds 4 bits big-endian, u13be(x) 13 bits, u32le(x) 32 bits little-endian, u1be(0) checks a reserved bit, .. b"RIFF" matches a byte-string prefix, and v128le(v) pulls 16 bytes straight into a SIMD V128.

An IPv4 header is the RFC 791 diagram, transcribed:

@bobzhang
bobzhang / README.md
Created September 2, 2026 09:56
MoonBit vs Rust: regex as a pattern (lexmatch/lexscan vs the regex crate)

MoonBit vs Rust: regex as a pattern (lexmatch / lexscan)

In MoonBit a regex literal re"..." is a pattern. It is compiled at build time, as binds the matched slice as a zero-copy StringView (or a Char for a single-char regex), with longest gives maximal munch, and before~ / after~ bind the unmatched prefix and suffix.

A whole lexer is one lexscan over a @lexbuf.StringScanner; the cursor advances for you:

@bobzhang
bobzhang / README.md
Created September 2, 2026 09:56
MoonBit vs Rust: pattern matching on JSON (one pattern per case vs serde_json get/and_then chains)

MoonBit vs Rust: pattern matching on JSON

One match on a Json value, one pattern per case. Object keys, string / number / bool literals, nested objects, arrays with rest (..), string-prefix patterns inside JSON strings (String([.. "refs/tags/", .. tag])), and "key is absent" ("milestone"? : None) all compose in a single pattern.

match event {
 { "action": "opened", "pull_request": { "draft": true, .. }, .. } =>
@bobzhang
bobzhang / tonyfettes-raylib_env.txt
Created February 26, 2026 14:32
moon build links non-main package as executable and fails with missing _main
Date: 2026-02-26T14:32:29Z
moon 0.1.20260224 (2288f02 2026-02-24)
Feature flags enabled: rr_moon_pkg
Darwin HongboZhangs-Mac-mini.local 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132 arm64
/Library/Developer/CommandLineTools
Apple clang version 17.0.0 (clang-1700.3.19.1)
Target: arm64-apple-darwin25.0.0
@bobzhang
bobzhang / Comparison of different langauges
Last active January 5, 2023 18:17
Type safe Alt-JS language comparison
A list of languages which compile to JS (Elm, Purescript, OCaml)
(Inspired by this thread: https://groups.google.com/forum/#!topic/elm-discuss/Um7WIBTq9xU)
They all support curry calling convention by default.
Some interesting results:
1. `min` is curried function, only OCaml(BuckleScript) managed to optimize this overhead.
2. All optimize the self tail call
3. Only BuckleScript and PureScript type-specialized comparison functoin (>=) and inlined
  • hello

external imul : int -> int -> int = "Math.imul" [@@bs.val]
  • hey

AsciiDoc User Guide

AsciiDoc is a text document format for writing notes, documentation,

let f x y = x + y
external to_str : 'a -> string = "js_anything_to_string"
external to_json_string : 'a -> string = "js_json_stringify"
let debug x = print_endline (to_str x )
let pprint x = print_endline (to_json_string x)
let rec fib = function
| 1 | 2 -> 1
| n -> fib (n - 1 ) + fib (n - 2)
(** Imperative style *)
let sum n =
let v = ref 0 in