ludic/docs/language/structure/kw-extern.md
Orkuncakilkaya 4c48077d68 refactor(lang): rename the fn keyword to function
Expand the function-declaration keyword to the full word across the whole
language and toolchain:
  fn name(...) -> T { ... }   ->   function name(...) -> T { ... }

Done as a self-hosting migration: teach the parser both spellings, reseed,
rewrite every .ludic definition to `function`, then drop `fn`. The compiler
now rejects `fn`. Touches the parser, all selfhost/tools/runtime/example/test
sources, the grammars (TextMate shared+vscode, ludic_syntax.h, JetBrains
LudicTokens.kt), the LSP and formatter, the Python doc/vocab tools
(check-impl, check-docs, validate, palette, test-lsp), and the docs
(fences, prose, kw-fn -> kw-function).

Reseeded; C-free bootstrap fixpoint holds. All suites green (45 regression,
24 self-host, 29 tool); the docs site generates and check.py passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 01:43:22 +03:00

1.3 KiB


id: kw-extern name: extern category: structure kind: keyword tokens: extern sig: extern function name(a: T) -> R = "symbol" tip: Bind a name to an external native symbol — the seam for platform and library calls. order: 12

An extern function declares a function whose body lives outside Ludic and binds it to a native symbol resolved at link time. It is the seam through which Ludic reaches anything with a native interface — a system library, a math routine, or even another .ludic file compiled as a module. You write the Ludic signature you want to call and give the real symbol name after =; the linker connects them (pass -L/-l to ludicc to point at the library). Types must match the foreign ABI, so map each parameter and the return to the right Ludic type (int, fixed, ptr, …).

Parameters:

  • a — a typed argument passed straight through to the foreign symbol
program Physics {
  extern function c_hypot(a: fixed, b: fixed) -> fixed = "hypot_fx"

  property Velocity { delta_x: int = 0, delta_y: int = 0 }
  model Projectile { Velocity }

  handler MeasureSpeed phase Update {
    for (velocity) in query [Velocity, {Projectile}] {
      let speed = c_hypot(a: fx(velocity.delta_x), b: fx(velocity.delta_y))
      Screen.status(str(flr(speed)))
    }
  }
}