Skip to content

Commit 4a7525f

Browse files
Feat: Improve python demo code snippet.
1 parent 961dd2c commit 4a7525f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

demo/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const WASM_SOURCES = DEV
77
: ['./compiler_lib.wasm'];
88
const FETCH_OPTS = DEV ? { cache: 'no-store' } : undefined;
99

10-
const DEFAULT_CODE = `def add(a: int, b: int) -> int:\n return a + b\nresult: int = add(13, 20)\nprint(result)`;
10+
const DEFAULT_CODE = `"""\nImplements a pure functional pipeline using head-tail recursion to avoid state mutation.\n\nReferences:\n* Backus, J. (1978). Algebra of Programs (Function composition).\n"""\n\ndef double(n: int) -> int:\n return n * 2\n\ndef square(n: int) -> int:\n return n * n\n\ndef apply_pipeline(value: int, steps: list) -> int:\n # Stop recursion when no steps remain\n if not steps:\n return value\n\n first_fn = steps[0]\n remaining_steps = steps[1:]\n\n return apply_pipeline(first_fn(value), remaining_steps)\n\ndef transform_list(elements: list, steps: list) -> list:\n # Stop recursion when list is empty\n if not elements:\n return []\n\n head = elements[0]\n tail = elements[1:]\n\n transformed = apply_pipeline(head, steps)\n\n return [transformed] + transform_list(tail, steps)\n\ndata: list = [1, 2, 3]\npipeline: list = [double, square]\n\nresult = transform_list(data, pipeline)\n\nprint(f"Input: {data}")\nprint(f"Output: {result}")`;
1111

1212
const CLS = { ok: 'ml-auto text-[#7daf7a]', err: 'ml-auto text-[#d67f6d]' };
1313
const MAX_LINES = 99;

0 commit comments

Comments
 (0)