Skip to content

EN Cookbook

Arena Agent edited this page Sep 18, 2026 · 2 revisions

Cookbook | دستورهای کاربردی

A typed function | تابع typed

func average(a: float, b: float) -> float {
    return (a + b) / 2.0;
}

say(average(10.0, 14.0));

Use annotations at public boundaries and in code where they clarify intent. Leave local expressions inferred when the result is obvious.

A data type with behavior | نوع داده همراه رفتار

struct Point { x: float, y: float }

impl Point {
    func translate(&mut self, dx: float, dy: float) {
        self.x = self.x + dx;
        self.y = self.y + dy;
    }
}

&mut self communicates that the method changes the receiver. این annotation فقط syntax نیست؛ قرارداد تغییرپذیری API را هم مشخص می‌کند.

A small command-line pipeline | pipeline ساده

func report(values) {
    for value in values {
        say("value = ${value}");
    }
}

report([3, 1, 4]);

Keep input parsing, transformation, and output in separate functions. This makes plix test suites smaller and compiler diagnostics easier to localize.

Debugging checklist | چک‌لیست رفع خطا

  • Run plix check before investigating runtime output.
  • Reduce a failing program to the smallest .px file.
  • Test the reduced case with both run and build.
  • If a borrow error appears, identify which call needs ownership and which only needs a borrow.
  • Do not use the native path as a substitute for checking: native compilation assumes the program passes the language checks.

Learning path: ← Architecture · Standard Library →

Clone this wiki locally