3 ms·
https://luafun.github.io/intro.html https://luafun.github.io/intro.html is the best I've found for performant stream-y transforms. But I tend to just believe in
by nikki93 6y ago
https://luafun.github.io/intro.html https://luafun.github.io/intro.html is the best I've found for performant stream-y transforms. But I tend to just believe in always writing for-loops because they are how computers actually work and IMO it's easier to reason about what they are doing (of course, encapsulating logic per element and so on into their own functions). C++'s STL stuff I think is actually also good / ok here and one exception I make because you can see the code generated and things get inlined, and things like `std::remove_if` or `std::lower_bound` are actually well implemented. The rest of the functional shenanigans are cool I think for their theory (eg. as far as applicative functors for parsing and whatnot); but I think if you care about performance, the data layout in memory for cache utilization seems to be what matters now. Clojure is ok yeah but IMO you should know that it's impl'd with structural sharing + GC and decide that that's the behavior you want. Here's eg. a library that does persistent data structures of that sort in C++: https://sinusoid.es/immer/ https://sinusoid.es/immer/ (no transients for maps though)
Re: the Lua / JS mismatch -- I think the main thing is that you kind of have to decide if a table is an array or not, and in a lot of cases there's no sensible thing here necessarily, especially if there are a lot of `nil`s in the array -- so is it a sparse JSON array or an object with those keys (stringified -- which is gnarly) or what? etc. You can see settings for this in lua-cjson [1], and the fact that the settings exist is the issue. It's not as bad for pure JSON as much as when you start wanting to do things like generate a diff from changes in the Lua side (that's when you start getting sparse arrays) and apply those to the same document in JS, or the other way round and so on. I wrote a real-time automatic diff sync'ing thing once that was something like this; and that was the main place where there the impedance mismatch came up. nil-null basically didn't matter -- I decided on one conversion and stuck with it (I basically decided we would not use `null` for anything -- just use something that represents the actual semantic thing you want instead).
Also FWIW, I don't find CL super 'functional'. Scheme and Clojure a little bit, sure. The most functional stuff I feel like is Haskell / ML. If it's just about closures--I feel like every language except C, Zig and Ada has closures these days.
Lua strings are pretty simple -- just an array and immutable (there's no COW because there is no W) and always interned. You have to build a new string with the modification you want. For a 'builder' approach usually the pattern is to accumulate a table then call `table.join`. Usually I manage fine with `str = str .. 'new stuff'` though unless it's in some hot code path.
[1] https://www.kyne.com.au/~mark/software/lua-cjson-manual.html#encode_sparse_array https://www.kyne.com.au/~mark/software/lua-cjson-manual.html...
- aasasd 6y ago> https://luafun.github.io/intro.html https://luafun.github.io/intro.html is the best I've found for performant stream-y transforms Thanks, I'll need to take a look at it.