After writing the loeb function in Emacs Lisp recently, it occurs to me that
it could be used to write an evaluation function for Org spreadsheet tables
that is both maximally efficient (in that no cell is calculated twice) and
always converges on a stable end result. The steps are as follows:

1. Use =org-table-to-lisp= to parse the Org table into a Lisp matrix (list of
   lists).

2. Map through all of the cells in this matrix, converting each into a closure
   that maps from a matrix of strings to a string.

   The work of each such closure is to calculate the formula for that
   particular cell using =org-table-eval-formula= — which may involve looking
   up the relevant cell, row or column formula from the table’s formula field
   — and resolving any cell references by looking up those values in the
   matrix argument.

3. Apply the relevant [[https://github.com/jwiegley/emacs-loeb][loeb]]
   function to this matrix. This does the work of resolving all references, so
   long as the table represents a directed, acyclic graph of data
   dependencies. If it does not, infinite recursion will result in a Lisp
   evaluation exception.

4. Render the final matrix return by =loeb=, which is a matrix of strings,
   back into the Org-table, honoring all formatting directives.

When I went looking at org-table.el, I find that it’s very much tailored to
work on the state of the buffer and its “work space”, and may not be so easy
to convert to a functional style, where instead we convert the table to a Lisp
data structure, operate on the data structure, and then render it back out to
a table.

Are there any org-table.el masters who might be interested in helping with
such a reworking of the calculation engine?

For some context:

  https://newartisans.com/2025/05/implementing-loeb-emacs-lisp/

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2

Reply via email to