Small experimental scripting language + interpreter in C.
- Feature overview
- Hello, MKS
- Language tour
- Entities & extend
- Imports & stdlib
- Watch / defer
- CLI
- Repo layout
- Docs
- Expressions: numbers, strings, arrays, indexing.
- Control flow:
if/else,while,for,repeat,break,continue. - Functions & recursion:
fnc name(args) -> ... <-,return. - Swap operator:
a <--> b;(fast in-place). - Defer & watch/on change.
- Entities (lightweight objects) + methods; extend built-ins (array/string).
- Imports with built-in std path (
std/math). - Friendly errors with hints; recursion-depth guard.
- Simple mark/sweep GC; sanitizer-friendly build.
using "std/math";
var x =: 10;
watch x;
on change x -> Writeln("x changed"); <-
x =: square(x); // triggers watcher
Writeln("result:", x);
Variables & swap
var a =: 1;
var b =: 2;
a <--> b; // swap
Control flow
if (a > 0) -> Writeln("positive"); <-
while (a < 5) -> a =: a + 1; <-
for (var i =: 0; i < 3; i =: i + 1) -> Writeln(i); <-
repeat 3 -> Writeln("ping"); <-
repeat i in 3 -> Writeln(i); <-
Functions
fnc add(a, b) ->
return a + b;
<-
Writeln(add(2, 3));
Tests
test "math add" ->
expect(1 + 1 ?= 2);
<-
entity User(name) ->
init -> self.name =: name; <-
method hi() -> Writeln("Hi ", self.name); <-
<-
var u =: User("Ann");
u.hi();
extend array ->
method sum() ->
var s =: 0; var i =: 0;
while (i < self.len()) -> s =: s + self[i]; i =: i + 1; <-
return s;
<-
<-
Writeln([1,2,3].sum()); // 6
using "path/to/file"; // .mks optional
using "std/math"; // built-in path
Resolution: current file dir → CWD → installed std path. A module runs once (duplicate/nested imports are skipped).
std/math.mks (pure MKS):
using "std/math";
Writeln(abs(-5));
Writeln(square(4));
Writeln(min(10, 3));
Writeln(max(10, 3));
watch x;
on change x -> Writeln("x changed to ", x); <-
defer -> Writeln("leaving scope"); <-
on change must be registered before the assignment you want to observe.
mks <file.mks> # run file
mks --repl # interactive REPL
mks --version
mks --help
Lexer/– tokensParser/– AST + parsingEval/– evaluationRuntime/– values, operators, modules, errorsenv/– variable scopesGC/– garbage collectorstd/– bundled stdlib (std/math.mks)examples/– runnable samplesdocs/– reference / guidestests/– golden tests (./tests.sh)
docs/REFERENCE.md— quick reference (syntax & examples).docs/USER_GUIDE.md— step-by-step guide (entities, extend, watch/defer, repeat, swap).
Active, experimental. APIs may change. Friendly errors should point to the fix; if not, please open an issue.