2 ms·
The article does not show much except TCO existing with Bun and JavaScriptCore. It uses a not very suitable mutable data structure to mutate it in each iteratio
by zelphirkalt 3y ago
The article does not show much except TCO existing with Bun and JavaScriptCore. It uses a not very suitable mutable data structure to mutate it in each iteration. I would say for that example it is almost better to use the for loop, since it looks very imperative anyway and using recursion to do mutating procedure calls does not give much benefit. It is a not so well chosen example.
- MrJohz 3y agoThat'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 ;)