3 ms·
That's mostly the point I'm trying to make! What would you see as a more convincing example of TCO in this context?
by MrJohz 3y ago
That's mostly the point I'm trying to make! What would you see as a more convincing example of TCO in this context?
- zelphirkalt 3y agoPerhaps an example using a persistent functional data structure would be good, but probably also more complex. Instead you could do some simpler example like factorial or fibonacci, which would usually run into a stack overflow, but due to Bun being based on JavaScriptCore not running into one. At first I wanted to suggest to implement Dijkstra's algorithm for finding shortest paths from a specific node to all other nodes, but then I found a mutation in my own implementation for updating the distances and routes to nodes tables, so I did not want to suggest something I hadn't fully done myself. But maybe, if you had something like functional hashes or similarly usable for the problem, you could do it. So I will link it here: https://notabug.org/ZelphirKaltstahl/guile-algorithms/src/839bb8a0d502727feab238e5ebaebb5f128c0891/graphs/lib/algorithms/dijkstra.scm https://notabug.org/ZelphirKaltstahl/guile-algorithms/src/83... Note, that I put a "warning" in there, at the place, where it still uses mutation. Potentially this could hinder parallelization. Not sure if applicable in this specific problem, but in general, if you want to parallelize an algorithm, it not having any mutation makes it much easier to parallelize it and use our modern machines, which have multiple cores. So shame on me for not having a mutation-free version yet ;)