John Wiegley <[email protected]> writes:
>> Ok. Let's go a full LLM craze now :)
>
> Alright, after many Claude-hours, I do believe all issues raised should be
> addressed, plus a host of new ones when I ran my own in-depth code review as
> well. Up to 174 tests now. Give this one a try!
>
> https://github.com/jwiegley/org-table-loeb
>
> Especially see comments in commit
> https://github.com/jwiegley/org-table-loeb/commit/c16ea6706e03e0ab10b185e24b495d12b2d00e23
Not yet converged :)
Let this human pass the next input from the mighty LLM.
(Jokes aside, iterative convergence of the cells is what I use by
myself, and I'd prefer to keep that feature)
In org-table-loeb.el buffer, I provide John Wiegley's
re-implementation of Org mode table formulas.
I am also providing the Org manual entries describing this functionality in the
context.
You can lookup org-table.el (large buffer) for the original implementation.
The John's rewrite is large and done by LLM, so I expect various subtle details
to
be inconsistent. Please look at the John's code and check if the code behavior
contradicts things documented in the manual.
If you do not find significant problems, search online for typical Org table
usage
examples and assess whether the new code can break them.
Before reasoning about the code problems, look at the org-table.el and
org-table-loeb.el and give a detailed answer, in plain text, about the code
logic. Not just high-level overview, but down to specifics of the functions,
catching notable implementation details.
You are NOT CONSTRAINED BY TIME. Feel free to do reasoning for as long as
needed.
# LLM response
*Contradictions with the manual and missing features*
1. *Range formulas (left-hand side)* – The manual describes =@1$2..@4$3== to
assign a formula to a rectangular range. The new code does *not* expand
left-hand side ranges; it only accepts single-cell targets (=@R$C=) or column
targets (=$C=). Row formulas (=@3==) are likewise unsupported.
2. *Named-field left-hand side* – The manual allows =$name== as a target. The
new code never substitutes named fields on the left-hand side; it only uses
=org-table-formula-substitute-names= on the right-hand side.
3. *Column creation* – The original engine can create new columns when a
formula targets a column beyond the current table width (controlled by
=org-table-formula-create-columns=). The loeb engine uses =org-table-to-lisp=,
which reflects the existing columns; out-of-bounds targets will cause an error.
4. *Column-width cookies* – The original =org-table-recalculate= wraps
evaluation in =org-table-with-shrunk-columns=, which temporarily expands
columns that have been narrowed by =<N>= width cookies. The loeb engine *omits
this wrapper*, so formulas may see truncated cell content if columns are shrunk.
5. Left-hand side expansion of =$<=, =$>=, =@<=, =@>= – While the
preprocessing step expands these references in formulas, the target parsing
does *not* expand them when they appear as the left-hand side of a formula
(e.g., =$<==). The original calls =org-table-formula-handle-first/last-rc= on
both sides.
6. *Duplicate-formula detection* – The original detects when several
field/range formulas try to set the same cell and raises an error. The loeb
engine does not perform this check; it simply overwrites with the last
definition.
7. *Iteration for convergence* – The manual describes =C-u C-u C-c *= to
iterate until the table stabilizes. The loeb engine detects cycles and errors
immediately; it never iterates. This is stricter but may break tables that rely
on iterative convergence (though such cases are likely cycles that would not
converge anyway [2026-02-05 Thu] Comment from human: Such cycles are useful for
simple iterative calculations that
rely on cell convergence. They do happen in real life usage and are quite
helpful).
*Potential subtle inconsistencies*
- *Order of expansions* – The original interleaves remote, named, first/last,
and hline expansions in a single pass (=org-table-formula-substitute-names=).
The loeb engine applies them in a fixed sequence, which could change the
meaning of edge-case references (e.g., =remote("table", @I$2)= where =@I=
should be expanded before remote resolution?).
- *=N= flag with ranges* – The manual states that the =N= flag forces numbers
and treats empty cells as =0=. The loeb engine applies =N= only to individual
cell references, not to range results (vectors). This matches typical usage but
could differ if a range contains non-numeric strings.
- *=@#= and =$#= substitution* – The manual says these are replaced by the
row/column numbers of the /target/ field. The loeb engine does this
substitution /before/ preprocessing, which is correct.
- *Hline-relative offsets* – The manual mentions =@III+2=. The loeb engine
supports =@I+N= offsets, but the implementation may misinterpret negative
offsets (e.g., =@I-2=) when the resulting row would be before the hline.
*Impact on typical usage*
- Common patterns (column formulas, field formulas with absolute/relative
references, ranges on the right-hand side, remote references, Calc/Lisp
formulas with format specifiers) should work unchanged.
- Examples from the Org-mode tutorial (column means, row-wise =vmean=, etc.)
will function.
- Advanced features that rely on left-hand side ranges, row formulas,
named-field targets, or automatic column creation will fail.
- Tables that use column-width cookies may produce incorrect results because
the loeb engine sees the displayed (truncated) content.
*Recommendation*
The loeb engine is a sophisticated rewrite that introduces explicit dependency
resolution and cycle detection, which is conceptually cleaner than the classic
iterative approach. However, before it can replace the classic engine, the
missing features listed above must be implemented. In particular:
- Expand left-hand side ranges and row formulas (call
=org-table-expand-lhs-ranges=).
- Handle named-field left-hand side targets (use
=org-table-named-field-locations=).
- Wrap evaluation in =org-table-with-shrunk-columns=.
- Integrate column-creation logic (respect =org-table-formula-create-columns=).
- Expand =$<=, =$>=, etc. in targets (call
=org-table-formula-handle-first/last-rc= on the left-hand side).
- Add duplicate-formula detection (mirror the original’s =seen-fields= check).
Until these are addressed, the loeb engine should be considered experimental
and unsuitable for general use.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>