News for hackers. Stuff that matters.
Re:Adding Window Functions to a Spreadsheet by shevy-java on Wednesday November 04, 2026 @10:44AM (#50367204)
The syntax is so archaic ... it really is anything but a thing of beauty.

    prev_balance = PREVIOUS(rec, order_by="Date").Running_Balance or 0
    prev_balance + $Amount
It's such a strange mix-up of stuff. PREVIOUS() is a macro or looks like one, right? But it is a function call assumingly. But then what's with .Running_Balance? Guess that also ties into a function. But why use different syntax for essentially the same thing? It seems rather weird to write code like that. What would the python variant be like? Or a DSL?

The syntax strangeness continues:

    rates = Rates.lookupRecords(Person=$Person, order_by="Rate_Start")
    rates.find.le($Date).Hourly_Rate
Does that really convey most easily what is wanted? It seems needlessly verbose. Why would it require both $Person and $Date? Should that not be easier to figure out in its own right? Is that efficient?

People need to remember that mentally, unless they use AI.

Re:Adding Window Functions to a Spreadsheet by paulfitz on Wednesday November 04, 2026 @10:50AM (#50367318)
It is straight Python. Yes the spreadsheet habit of making functions SHOUT does look weird mixed in with Python syntax.

PREVIOUS returns a record, then .Running_Balance pulls out one field of it.

Re:Adding Window Functions to a Spreadsheet by whizzter on Wednesday November 04, 2026 @10:53AM (#50367374)
What parts are Python and how does one know where the classic Spreadsheet functionality ends and Python starts ?
Re:Adding Window Functions to a Spreadsheet by librasteve on Wednesday November 04, 2026 @11:21AM (#50367819)
that’s why https://omasheet.org has its own DSL. that said it’s no doubt go some wrinkles so I’ll be reviewing all the comments on this hn post very carefully
Re:Adding Window Functions to a Spreadsheet by whizzter on Thursday November 05, 2026 @08:58AM (#50379121)
Not entirely uninteresting, wrote some thoughts in your main comment thread.
Re:Adding Window Functions to a Spreadsheet by dsagal on Wednesday November 04, 2026 @12:45PM (#50369002)
"classic Spreadsheet functionality" is just familiar Excel functions with uppercase names implemented in Python, right here: https://github.com/gristlabs/grist-core/tree/main/sandbox/gr...

E.g. UPPER($A) is just a function that calls $A.upper(). And $A is just syntactic sugar over rec.A.

PREVIOUS() is only special in that it automatically creates an index, which is important for efficiency. But generally you can look up a set of records and write multi-line Python code to do whatever you want with it and return a value. And it all runs in a sandbox with no access to anything except this document's data.

Re:Adding Window Functions to a Spreadsheet by whizzter on Thursday November 05, 2026 @06:59AM (#50378117)
Oh, so this is something Grist specific rather than something inherited from Excel? (I remember reading sometime back that MS was replacing VBA with Python)
Re:Adding Window Functions to a Spreadsheet by chii on Wednesday November 04, 2026 @10:58AM (#50367450)
That's what makes it clunky. Returning a record is OK, but then a record is basically what spreadsheets are (ala, a table). Except records are named columns in a spreadsheet, and accessing it using a dot syntax looks out of place imho.

I reckon it makes more sense to return a table, and then have an index lookup in that table: e.g., index(PREVIOUS(blah_blah), column). Then you can also use an indirection to choose which column from another cell if desired.

This is how google finance in sheets returns some data (like exchange rates, iirc).

Re:Adding Window Functions to a Spreadsheet by whizzter on Wednesday November 04, 2026 @10:52AM (#50367357)
I think it's an push in Spreadsheets to become more "DB-alike" for less arbitrary results (like in the problem example the article starts out with) but kind-of misguided since it's complicated to do "easy things".

The root issue is that there's almost 50 years of spreadsheet syntax to consider and not colliding with.

Re:Adding Window Functions to a Spreadsheet by librasteve on Wednesday November 04, 2026 @11:24AM (#50367883)
hmmm sigils, eh?