首页 > AI前沿 > Sexp Matrix

Sexp Matrix

Hacker News 2026-11-19 04:01 16 阅读 查看原文
(lisper :icy) Craft Ideas Here is a simple idea. Could each row in a spreadsheet be represented as a self-contained S-expression? Could we evaluate these expressions remotely and asynchronously, then chain the rows together into a processing pipeline? What if we designed a new kind of spreadsheet where each row is a rich, editable S-expression? Let’s explore this idea by formally representing a spreadsheet as a Matrix. S-Matrix Consider matrix S where the first element in a row is always a function. The values in the remaining cells are either symbols, values or s-expressions. S = ( + 1 2 3 max 10 (+ 20 10) 5 avg 10 (compute-discount 100) (/ 10 2) ) Given a row with n elements, the row function C0 can be applied as C0:C1 → Cn. Cn+1 contains the output of C0:C1 → Cn. The matrix can be sparse or transposable. Matrix S can then be represented as a list of s-expressions. This is the core idea. '((+ 1 2 3) (max 10 10 (+ 20 10)) (avg 10 (compute-discount 100) (/ 10 2))) This list is eval’d by an external or remote s-expression evaluator. That evaluator has a rich library of functions to do sophisticated, asynchronous tasks. (apply (symbol (first row)) (map eval (rest row)) S-Matrix has other interesting properties which is beyond the scope of this discussion. Let’s quickly dive into some examples, to demonstrate the core idea. Examples Our first example is a matrix that computes the shipping fees for each cart total and other parameters. +----------------+----------------+----------------+----------------+----------------+ | function | cart.total | customer.tier | customer.zip | shipping.fees | +----------------+----------------+----------------+----------------+----------------+ | find-fees | 1000 | gold | (verify 12345) | ? | +----------------+----------------+----------------+----------------+----------------+ | find-fees | 2000 | silver | 45678 | ? | +----------------+----------------+----------------+----------------+----------------+ This is equivalent to the following on the server. (find-fees 1000 :gold (verify 12345)) find-fees is a remote function that could be a pre-defined function, AWS Lambda, a microkernel or a LLM agent. find-fees can actually be a sophisticated function that takes a lot more parameters into consideration. It could have fees waived for certain zip codes. It could take into account the current datetime and so forth. It could be using LLMs to determine the shipping fees. If you do not want find-fees to be pre-defined remote function you could inline the function. Something like the following in the function column. (fn [args] (cond (= (nth args 1) :gold) 30 (= (nth args 1) :silver) 50 (> 4000) 10)) Another example, as shown below, is to compute the account balance by having functions that fetch the actual balance for different financial buckets. Now, this table or matrix is not a static one. It actually is a representation of the actual balance. The functions are remote, asynchronous and arguably secure. +---------------+---------------+---------------+---------------+ | fn | bucket | spend | balance | +---------------+---------------+---------------+---------------+ | bank1-balance | house | (- 1000 30) | 4500 | +---------------+---------------+---------------+---------------+ | bank2-balance | education | (- 1000 10) | 2010 | +---------------+---------------+---------------+---------------+ | bank3-balance | food | (- 500 500) | 1000 | +---------------+---------------+---------------+---------------+ | hsa-balance | health | (- 300 100) | 2300 | +---------------+---------------+---------------+---------------+ Let’s try another example: Verifying documents - you could think of it as Truthy matrix: +----------------+----------------+----------------+----------------+----------------+ | Document Type | Name | State | Expiry | Valid? | +----------------+----------------+----------------+----------------+----------------+ | driver-license | Bob Smith | CA | 10-20 | No | +----------------+----------------+----------------+----------------+----------------+ | bank-statement | Joel Foo | FL | 11-01 | Yes | +----------------+----------------+----------------+----------------+----------------+ | passport | John Bar | IL | 01-01 | No | +----------------+----------------+----------------+----------------+----------------+ Recall that the last column is the output of the row function. In the first row, driver-license is a function that looks at the field values and verifies if the document is valid. (driver-license "Bob Smith" "CA" "10-20") -> No This matrix — a list of S-expressions — was probably generated by a document-extraction process. The idea that code is data applies only to S-expressions. Hopefully, this gives you an idea of what matrices with remotely evaluated S-expressions could be used for. Now let’s apply the concept to something more familiar: spreadsheets. Spreadsheets Grids and matrices are often easiest to visualize as spreadsheets. But modern spreadsheets are highly GUI-centric with a zillion buttons, and most of their functions run locally, which may not be adequate if they are computationally expensive. What if we reimagined spreadsheets around remote functions, with each row containing a list of S-expressions? Instead of treating cells as containers for values, we’d treat them as slots for S-expressions. The spreadsheet could include an editor for writing complex expressions, or let users reference code through a URI—such as a Git or HTTP link. The expressions would be evaluated dynamically. Entangle is a prototype showcasing this concept. It’s a tiny application written in Clojure. git clone https://git.sr.ht/~icylisper/entangle cd entangle clojure -Srepro -M -m entangle.main ;=> Listen HTTP on port 8000 We can test that the API works using csv data. sample.csv +,1,2,3 *,4,5,6 +,(+ 2 3),2,(- 5 1) curl -X PUT http://localhost:8000/csv -H 'Content-Type: text/csv' --data-binary @sample.csv +,1,2,3,6 *,4,5,6,120 +,(+ 2 3),2,(- 5 1),11 We could also capture the output of any row and use it in subsequent rows kind of creating a pipeline or as mathematicians call it Transient Matrix. +,1,2,3 *,$0 +,$0,$1 Where $N specifies the nth row. We could also do map-reduce kinda computation using the simple reduce function and $* macro/notation. +,1,2,3 *,$0 +,$0,$1 reduce,$* Additionally, the row function could point to an LLM agent that computes a value from a collection of expressions, text, or other data. It could just as easily invoke a remote serverless function or call a REST endpoint. Yo enough talk. Let’s see something in action. Below is a screencast showing basic usage of the spreadsheet UI. It’s a single page HTML - just do open index.html When we hit compute button, it sends the list of s-expressions to the Entangle REST API. The backend evals the s-expressions and returns the output asynchronously (via websocket). The receiving client filled the last column in each row with the corresponding result. Notice in the screencast that we can edit the s-expression in an editor (Yes, you can open it in emacs too!). The first cell’s s-expression is either a symbol or an anonymous function. The anonymous function always takes the rest of the row as an arg. Each s-expression evaluation takes it’s own time. The server can decide to parallelize the processing of these expressions. The goal of entangle is to showcase a new way to think about spreadsheets - as a matrix of s-expressions that are remotely evaluated. Scribbled on 11-06-2026. No LLMs used. Prior Art: Cells-gtk in common-lisp. Not strictly s-epxressions but has the idea of passing expressions between cells. Zen expression language uses javascript v8 engine to run scripts as formulas - similar to classic spreadsheets. org-mode as a spreadsheet, while using infix operators, is way more powerful than GUI-based spreadsheets. () Name: Comment Post Comment