#!/usr/bin/env python3 """Format probe — M-expressions. McCarthy's original Lisp notation: `head[arg1; arg2; ...]` — explicit structure (brackets + semicolons) but in the function-call shape `f[x; y]` that LLMs know from C/Python/JS. Tests the "more explicit structure helps" finding in a familiar guise. Own literal parser (atoms verbatim, whitespace-agnostic), round-trip-verified before judging output. Same ablation ladder. Reads $IONOS_API_TOKEN (never printed). Live IONOS — run with consent. """ from __future__ import annotations import json, os, re, subprocess, urllib.request from pathlib import Path ENDPOINT="https://openai.inference.de-txl.ionos.com/v1/chat/completions" MODEL="Qwen/Qwen3-Coder-Next" REPO=Path(__file__).resolve().parents[2] AIL=os.environ.get("AIL_BIN", str(REPO/"target/debug/ail")) DOC=REPO/"experiments/2026-05-12-cross-model-authoring/qwen-mexpr.md" def tokenize(s): t=[];i=0 while i=0 else body.strip() def evaluate(mx,expected): try: plain=from_mexpr(mx) except Exception as e: return "convert",f"own parser rejected output: {e}","" m=re.search(r"\(module\s+([A-Za-z_][A-Za-z0-9_]*)",plain) name=m.group(1) if m else "m" f=Path(f"/tmp/abl/{name}.ail"); f.parent.mkdir(exist_ok=True); f.write_text(plain+"\n") chk=subprocess.run([AIL,"check",str(f)],capture_output=True,text=True) if chk.returncode!=0: return "check",(chk.stderr or chk.stdout).strip(),plain if expected is None: return "green","(check-only)",plain run=subprocess.run([AIL,"run",str(f)],capture_output=True,text=True) if run.returncode!=0: return "run",(run.stderr or run.stdout).strip(),plain if run.stdout!=expected: return "output",f"got {run.stdout!r}, expected {expected!r}",plain return "green",run.stdout,plain def main(): log=["# Qwen format probe — M-expressions `head[a; b]`\n", f"**Model:** {MODEL}; single-shot; own literal parser (atoms verbatim).\n","---\n"] summary=[] for sid,ctx,task,exp in STAGES: resp,usage=call(ctx,task); mx=extract(resp) stage,fb,plain=evaluate(mx,exp) ok=stage=="green"; mark="✅ green" if ok else f"❌ {stage}" summary.append((sid,mark)); print(f"{sid}: {mark}") log+=[f"## {sid} — {mark}", f"\ntokens: prompt={usage.get('prompt_tokens','?')} completion={usage.get('completion_tokens','?')}\n", "model output:\n```\n"+mx[:1400]+"\n```\n", ("converted Form-A:\n```\n"+plain[:1100]+"\n```\n" if plain else ""), ("" if ok else f"**{stage}:**\n```\n{fb[:600]}\n```\n")] log+=["\n---\n## Ladder\n"]+[f"- {s}: {m}" for s,m in summary] DOC.write_text("\n".join(log)); print("doc →",DOC) if __name__=="__main__": main()