MALDA™ Reference Manual

The AI-First Programming Language - Version 1.0.39

35. Examples

This chapter is an index, not a second tutorial. Beginners should use Learn MALDA. 35.0 is the offline characteristic sample. 35.1 maps Examples/ folders to chapters. 35.2–35.5 are one snippet per track (agent, game, UI, property). Scaffolding is 35.6. Full listings live under Examples/README.md. The core course ends at offline prompt eval (Examples/Basics/prompt_eval.malda), not the gradebook. After that, follow Learn MALDA — After the core path.

35.0 First Look

Characteristic constructs, no API key. Same program as Examples/Basics/first_look.malda and the Home Quick Start. -> Review binds the prompt to the schema. Without await, the call is a rendered template; validate("Review", …) is the same check await would run on the model JSON. Schema syntax: 4.6.

schema Review {
    summary: string;
    issues: string[];
}

prompt codeReview(code, language) -> Review {
    system: "You are an expert reviewer of {language}.",
    user: "Review this {language} code:\n\n{code}"
}

var rendered = codeReview("function add(a, b) { return a + b; }", "javascript");
io.print(rendered.user);

var checked = validate("Review", {
    "summary": "Looks fine",
    "issues": []
});
if (checked.ok) {
    io.print("schema ok: " + checked.data.summary);
} else {
    io.print("schema failed: " + checked.error);
}

35.1 Examples catalog

Each folder’s metadata.json may tag requires: offline (default), network, api-key, or db. Hello World is Examples/Basics/hello_world.malda — chapter 12, not a second listing here. The complete starter is Examples/Basics/complete_starter_program.malda. The course mini project is Examples/Basics/gradebook.malda. The core course ends at Examples/Basics/prompt_eval.malda.

FolderFocusTypical requiresChapter
Basics/Syntax, control flow, functions, schema + validateoffline3–12, 4.6
Algorithms/Hanoi, search, sort, DPoffline8, 9
OOP/Classes and inheritanceoffline11
Prompts/prompt, RAG pipes, evalPromptapi-key (most)10
Agents/, AI_LLM/Agents, tools, LLM clientsapi-key19
Web/HttpServer, REST, ui.*, JS DOMnetwork / offline25–31
Games/game.* / three.* (JS target)offline28
Workflows/Durable workflow / stepoffline23
Testing/malda test, propertiesoffline36
Actors/spawn / send / onoffline18
ACP/, MCP/Agent / Model Context Protocolnetwork / api-key22, 21
Databases/, Graphs/, VectorDB/SQL, graphs, embeddingsdb / offline17, 15, 16
Memory/, Tools/, Plan/GraphMemory, file tools, plansapi-key / offline20, 19
Assistant/, Arduino/Assistant + skills; device sketchesapi-key / hardware34, 33

More folders (AI_Theory/, SpectreConsole/, RalphWiggum/, …) are listed in Examples/README.md. The neural-nets kit (math.matmul, perceptron / XOR / softmax, OnnxModel) is 14. Neural Nets. Convolution is 14.11.6. A net built from smaller nets is 14.10.1. RAG pipes: Examples/Prompts/rag_pipeline.malda — chapters 10 and 16, not a dump here.

35.2 Agent

Host-only: needs an LLM client. Same idea as Examples/Agents/. Language: 19. Agent Orchestration.

var client = new OpenRouterClient();
var agent = new Agent(
    "Assistant",
    "helper",
    "You are a helpful assistant.",
    client
);

var response = agent.think("What is 2+2?");
io.print(response.content);

35.3 Game

JavaScript target only. Preview with malda play app.malda (live reload unless --no-watch). Canvas / three.* / @shader() stay in 28. Same paddle as Examples/Games/game_bounce.malda:

var x = 100;
var speed = 220;

function update(dtMs) {
    var step = (speed * dtMs) / 1000;
    if (game.isKeyDown("arrowleft")) {
        x = x - step;
    }
    if (game.isKeyDown("arrowright")) {
        x = x + step;
    }
}

function render() {
    game.clear();
    game.fillRect(x, 140, 40, 40, "#33cc66");
    game.drawText("Use arrows", 10, 24, "#ffffff", "14px monospace");
}

game.createCanvas(640, 360, "#app");
game.setBackground("#202830");
game.start(update, render);

Create the canvas before drawing. Scale movement by dtMs. Load malda-js-runtime.js before the compiled script. Playable GPU billiards: 39.

35.4 Server-driven UI

Language API: 26 (start at 25). Offline samples under Examples/Web/: ui_event_loop.malda, ui_counter_dashboard.malda, ui_form_workflow.malda.

var tree = ui.column({
    "children": [
        ui.text({ "text": "Hello" }),
        ui.button({ "id": "ok", "text": "OK" })
    ]
});
ui.mount("root", tree);
ui.render();

35.5 Property tests

property intIdentity(x) {
    return (x + 0) == x;
}
malda test --iterations 80 --seed 1337
malda test --format ci
malda test --write-regression --regression-dir ./artifacts/regressions

Full guidance: 36. Property Testing. Samples: Examples/Testing/.

35.6 Scaffolding

CLI index: 2.0. Full-stack flow: 31.

malda new webapi my-api
malda new fullstack my-app
malda new game my-game
malda new game my-scores --fullstack
malda new agent my-agent
malda new webapi my-api --name SalesPortal
malda new fullstack . --force
malda new webapi api-lite --no-tests

Generated starters include default malda test conventions and config placeholders. The game template’s next step is malda play app.malda. malda new game --fullstack is a score API compiled with --mode fullstack, not malda play. The agent template is offline and cap-confined; next step is malda app.malda.

See Also