Summary
While addressing Gemini's review on #1304 (which caught 17 error() calls inside still-untranslated JavaScript blocks), I scanned all of xml_py for the same underlying problem: content inside <PYTHON>/<PYTHONINLINE>/<PYTHON_RUN>/<PYTHON_TEST> tags that is still literal, untranslated JavaScript (function declarations, const/let, ternaries, semicolons, ===) rather than real Python.
This is much bigger than the 17 lines Gemini flagged — roughly 90 code blocks across 19 files, heavily concentrated in the chapter 5.5 compiler section. One file (xml_py/chapter5/section3/subsection2.xml) had its entire PYTHON_RUN block still in JS — all 13 of its error() calls were flagged.
There's already a FIXME comment in the source acknowledging this in at least one spot (xml_py/chapter5/section5/subsection2.xml:796: <!-- FIXME: This SPLIT.JAVASCRIPT contains a lot of SCHEME. Remove. -->), so this is a known, not-yet-finished conversion gap rather than a surprise.
Methodology (and caveats)
Regex scan requiring at least 2 distinct JS-only signals per code block (function name(, const x =, let x =, =>, ===, !==, trailing ;, ternary a ? b : c). This has some false positives from prose that happens to use the English word "function" or contain ?/: punctuation near each other (e.g. exercise text, subheadings) — I filtered out the ones I could identify manually, but a human skim is still worth it before treating the full list as ground truth. It should not have significant false negatives for genuine top-level function/const/let code, which is the bulk of what's below.
Two distinct shapes of the same problem:
- Implementation code still written as JS (function bodies, register-machine ops, etc.) — needs real translation to Python (
def, no semicolons, if/else instead of ternaries, etc.)
- Demonstration input strings (e.g.
parse_and_evaluate("... function factorial(n) {..."), compile(parse(function factorial...))) — these feed a JS-syntax program into an evaluator/compiler being demonstrated; for the Python edition these example programs should presumably also be Python syntax once translated.
Representative examples (genuine code, not prose)
xml_py/chapter5/section3/subsection2.xml:817 // TYPED POINTERS const NUMBER_TYPE = "number"; ...
xml_py/chapter5/section5/subsection2.xml:1021 function compile_lambda_expression(exp, target, linkage) { const fun_entry = ...
xml_py/chapter5/section5/subsection3.xml:603 function compile_function_call(target, linkage) { const primitive_branch = ...
xml_py/chapter5/section4/subsection4.xml:1170 function fib(n) { return n < 2 ? n : fib(n - 1) + fib(n - 2); }
xml_py/chapter4/section1/subsection6.xml:360 function f(x) { return ((is_even, is_odd) => is_even(is_even, is_odd, x))...
xml_py/chapter3/section3/subsection1.xml:248 const z = pair(y, tail(x));
Rough distribution (block count per file, after removing obvious prose false-positives)
2 xml_py/chapter2/section3/subsection2.xml
3 xml_py/chapter3/section3/subsection1.xml
2 xml_py/chapter4/section1/subsection2.xml
4 xml_py/chapter4/section1/subsection4.xml
2 xml_py/chapter4/section1/subsection6.xml
2 xml_py/chapter4/section1/subsection7.xml
7 xml_py/chapter4/section2/subsection2.xml
1 xml_py/chapter4/section3/section3.xml
8 xml_py/chapter4/section3/subsection3.xml
3 xml_py/chapter5/section3/subsection1.xml
1 xml_py/chapter5/section3/subsection2.xml (only 1 block, but that block is the file's entire PYTHON_RUN driver-loop/simulator)
5 xml_py/chapter5/section4/subsection2.xml
13 xml_py/chapter5/section4/subsection4.xml
2 xml_py/chapter5/section5/subsection1.xml
13 xml_py/chapter5/section5/subsection2.xml
6 xml_py/chapter5/section5/subsection3.xml
7 xml_py/chapter5/section5/subsection4.xml
4 xml_py/chapter5/section5/subsection5.xml
10 xml_py/chapter5/section5/subsection7.xml
~42 of the ~90 blocks are in chapter 5.5 alone (the compiler — subsections 1 through 7), which reads as essentially not yet translated to Python. Chapters 5.3/5.4 (register-machine simulator, explicit-control evaluator) and scattered spots in chapters 2–4 make up the rest.
Suggested next step
This is a content-translation task, not a mechanical fix — I haven't attempted it and don't think it's something to script the way the argument-order fix was. Given the size (most of chapter 5.5), it's probably worth scoping/prioritizing deliberately rather than doing it as a drive-by fix.
Summary
While addressing Gemini's review on #1304 (which caught 17
error()calls inside still-untranslated JavaScript blocks), I scanned all ofxml_pyfor the same underlying problem: content inside<PYTHON>/<PYTHONINLINE>/<PYTHON_RUN>/<PYTHON_TEST>tags that is still literal, untranslated JavaScript (functiondeclarations,const/let, ternaries, semicolons,===) rather than real Python.This is much bigger than the 17 lines Gemini flagged — roughly 90 code blocks across 19 files, heavily concentrated in the chapter 5.5 compiler section. One file (
xml_py/chapter5/section3/subsection2.xml) had its entirePYTHON_RUNblock still in JS — all 13 of itserror()calls were flagged.There's already a
FIXMEcomment in the source acknowledging this in at least one spot (xml_py/chapter5/section5/subsection2.xml:796:<!-- FIXME: This SPLIT.JAVASCRIPT contains a lot of SCHEME. Remove. -->), so this is a known, not-yet-finished conversion gap rather than a surprise.Methodology (and caveats)
Regex scan requiring at least 2 distinct JS-only signals per code block (
function name(,const x =,let x =,=>,===,!==, trailing;, ternarya ? b : c). This has some false positives from prose that happens to use the English word "function" or contain?/:punctuation near each other (e.g. exercise text, subheadings) — I filtered out the ones I could identify manually, but a human skim is still worth it before treating the full list as ground truth. It should not have significant false negatives for genuine top-levelfunction/const/letcode, which is the bulk of what's below.Two distinct shapes of the same problem:
def, no semicolons,if/elseinstead of ternaries, etc.)parse_and_evaluate("... function factorial(n) {..."),compile(parse(function factorial...))) — these feed a JS-syntax program into an evaluator/compiler being demonstrated; for the Python edition these example programs should presumably also be Python syntax once translated.Representative examples (genuine code, not prose)
Rough distribution (block count per file, after removing obvious prose false-positives)
~42 of the ~90 blocks are in chapter 5.5 alone (the compiler — subsections 1 through 7), which reads as essentially not yet translated to Python. Chapters 5.3/5.4 (register-machine simulator, explicit-control evaluator) and scattered spots in chapters 2–4 make up the rest.
Suggested next step
This is a content-translation task, not a mechanical fix — I haven't attempted it and don't think it's something to script the way the argument-order fix was. Given the size (most of chapter 5.5), it's probably worth scoping/prioritizing deliberately rather than doing it as a drive-by fix.