{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "concise-intro",
      "metadata": {},
      "source": "# Aner: concise methods\n\nUse your installed Aner executable and the compatible VS Code extension (**0.1.16** for this example). Follow the versions recommended together by your release; see `docs/INSTALLATION.md` and `docs/VSCODE.md`. Choose **Run All**. Cells share a native Aner session. Restart before rerunning the class definition cell.\n\nFields stay typed and private by default. Methods can omit `self` and `-> Result`; parameters still have explicit types.\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "concise-definition",
      "metadata": {},
      "outputs": [],
      "source": [
        "// Input types are explicit; receiver and result types can be inferred.\n",
        "class Cell<T> {\n",
        "    let initial: T\n",
        "    var value: T\n",
        "\n",
        "    fn get() { return value }\n",
        "    fn set(value: T) { self.value = value }\n",
        "    fn reset() { set(initial) }\n",
        "    fn preview() {\n",
        "        let value = initial\n",
        "        return value\n",
        "    }\n",
        "}\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "concise-shadowing",
      "metadata": {},
      "source": "## Read and change the value\n\n`get()` reads the field directly. In `set(value: T)`, the parameter shadows the field, so `self.value = value` names both unambiguously. These outputs are **10**, then **25**.\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "concise-set",
      "metadata": {},
      "outputs": [],
      "source": [
        "let counter = Cell<Int64>(initial: 0, value: 10)\n",
        "print(counter.get())\n",
        "counter.set(25)\n",
        "print(counter.get())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "concise-local",
      "metadata": {},
      "source": "## A local name can shadow a field\n\n`preview()` declares a local `value`. It returns the initial value (**0**) without changing the stored value (**25**).\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "concise-preview",
      "metadata": {},
      "outputs": [],
      "source": [
        "print(counter.preview())\n",
        "print(counter.get())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "concise-reset",
      "metadata": {},
      "source": "## Call another method on the same object\n\n`reset()` calls `set(initial)` without spelling `self`. It infers `Unit` because it returns no value. The stored value becomes **0**. Explicit `self` and return annotations remain accepted. Value return inference cycles need an explicit result annotation; recursive Unit methods can omit it.\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "concise-reset-run",
      "metadata": {},
      "outputs": [],
      "source": [
        "counter.reset()\n",
        "print(counter.get())\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "name": "aner",
      "display_name": "Aner",
      "language": "aner"
    },
    "language_info": {
      "name": "aner",
      "file_extension": ".aner",
      "mimetype": "text/x-aner"
    },
    "aner": {
      "status": "example",
      "execution_mode": "persistent-session"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
