News for hackers. Stuff that matters.
Re:A look at Unison: a revolutionary programming language by __MatrixMan__ on Wednesday January 11, 2023 @12:26AM (#34335303)
I'm not an expert at JS internals, but I'm under the impression that if you call a function ten times, its code has to be interpreted ten times, so you get ten, temporary, abstract syntax trees. Such is life in interpreter-land--the code is authoritative, the instructions are ephemeral.

My impression of Unison is that if you want to call a function ten times, you just need to evaluate that code into an AST once. Once you have the hash of that AST, you can delete the code and still call the function 9 more times without having to bother with building the tree each time.

I don't know what to call it, but I don't think it's interpreted because you don't need the code to run it (except the first time, which is how you know find the hash of the function).

Re:A look at Unison: a revolutionary programming language by goto11 on Wednesday January 11, 2023 @01:35AM (#34335750)
> I'm not an expert at JS internals, but I'm under the impression that if you call a function ten times, its code has to be interpreted ten times, so you get ten, temporary, abstract syntax trees.

This is not the case even in an interpreted language. You only need to build an AST once, at parse time. In JavaScript the AST is then compiled into byte code or machine code depending on the implementation.

Re:A look at Unison: a revolutionary programming language by __MatrixMan__ on Wednesday January 11, 2023 @02:06AM (#34335892)
Sorry, let me rephrase.

In JS, if 1 developer and 9 users with a total of 10 separate browser instances all call the same function, the code will be parsed 10 times.

In Unison, the AST is generated by the developer, cached, and the 9 users can call it by hash (assuming they have access to that database where the AST lives) without reparsing the code.

Re:A look at Unison: a revolutionary programming language by goto11 on Wednesday January 11, 2023 @11:28AM (#34340269)
So the AST is transferred over the wire? How is it serialized?
Re:A look at Unison: a revolutionary programming language by zawodnaya on Wednesday January 11, 2023 @06:47PM (#34346804)
It’s a binary-encoded merkle tree
Re:A look at Unison: a revolutionary programming language by __MatrixMan__ on Wednesday January 11, 2023 @11:41PM (#34349302)
It's in a sqlite database. Unison doesn't prescribe how those are passed around, but since everything is content addressed there are never any collisions. You can always merge two of them into one without having to resolve conflicts and without breaking anything.

The way I intend to use it is that users periodically fetch the codebases from all of the developers that they trust. This has no immediate effect because you're still calling the same function that you're used to. So the sync can be very latency tolerant.

Then, when you decided to use the new version of something, you call the new hash. If something goes wrong, you just go back to calling the old hash--atomic upgrade/downgrades, no merge conflicts.