{
 "meta": {
  "title": "Polyglot Pipeline — The Crush Language Guide",
  "description": "Generated from examples/async-dom.md of The Crush Language Guide (https://docs.crushlang.org/examples/async-dom.html). Edit the guide, not this file: it is regenerated on every build.",
  "frontends": [
   "crush"
  ],
  "author": "The Crush Language Guide",
  "tags": {
   "source": "examples/async-dom.md",
   "guide_url": "https://docs.crushlang.org/examples/async-dom.html",
   "generator": "scripts/build-notebooks.py"
  }
 },
 "cells": [
  {
   "id": "examples-async-dom-md-1",
   "kind": {
    "type": "markdown"
   },
   "source": "# Polyglot Pipeline\n\nThe same data, handled by the language best suited to each step, with Crush\nvariables as the glue. This replaces an earlier \"Async LLM Dashboard\" page whose\n`dom.*`, `seahorse` and `async`/`await` calls do not run in the current\ntoolchain.\n\nRun it with `crush run --polyglot poly.crush` (needs `python3`, `node` and `bash`\non `PATH`; `crush doctor` checks).\n\n> Verified against crush-ast `v0.13.0` (`dc0d0278`, 2026-12-03).\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "examples-async-dom-1",
   "kind": {
    "type": "crush"
   },
   "source": "// Three languages, one program. Values flow through Crush variables.\nlet numbers = [3, 1, 4, 1, 5, 9, 2, 6]\n\n@python -> mean {\nimport statistics\nmean = statistics.mean(numbers)\n}\n\n@javascript -> spread {\nconst spread = Math.max(...numbers) - Math.min(...numbers)\n}\n\n@python -> line {\nline = f\"mean={mean} spread={spread}\"\n}\nprint(line)\n\n@bash {\necho \"bash: $(echo done)\"\n}\nprint(\"\")\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "needs-host"
    ],
    "extra": {
     "guide": {
      "src": "examples/async-dom.md:14",
      "browser": "host",
      "why": "uses `@bash` blocks (polyglot), which the in-browser runtime does not provide",
      "expect_output": "mean=3.875 spread=8\nbash: done\n"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "examples-async-dom-md-3",
   "kind": {
    "type": "markdown"
   },
   "source": "**What this shows:**\n\n- `@python -> mean`: the block reads the Crush variable `numbers` (inputs are\n  automatic) and declares `mean` as its output, which becomes a Crush variable\n- `@javascript -> spread`: the same protocol; `spread` comes back as a number\n- the second `@python` block reads both earlier outputs, because they are Crush\n  variables now\n- `@bash`: only its printed output comes back. It could read a Crush variable\n  by naming it (`$name`), but it has no way to hand a value back, which is why the\n  formatting is done in Python\n- block output is trimmed and has no trailing newline, which is why `print(\"\")`\n  is used to finish the line\n- all three run as ordinary subprocesses with your user's authority — see\n  [Polyglot Programming](https://docs.crushlang.org/crush/polyglot.html#sandbox-and-authority)\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  }
 ]
}
