9 ms·
Looks somewhat ugly and also slow. (each element is processed in a separate process)
by Ono-Sendai 12y ago
Looks somewhat ugly and also slow. (each element is processed in a separate process)
- bismark 12y agoThese are Erlang VM processes which are actually quite fast. Re ugly: well, eye of the beholder I suppose.
- Ono-Sendai 12y agoHere's a map in my functional language (winter). It's not parallel yet, that shouldn't affect the syntax though. (map is already manifestly parallel) def square(float x) float : x*x def main(array<float, 256> a) array<float, 256> : map(square, a)
- nine_k 12y agoNow make it efficiently parallel and show us the implementation. Then we could compare it with the Elixir snippet, which does just that.
- kbenson 12y agoWell, if we are putting forth other languages, here's Perl 6: sub pmap(Code $func, @items) { return await @items.map: { start { $func($_) } } }
- azdle 12y agoRight, but in the erlang VM (and thus Elixir), processes are not OS processes, they are very very small processes internal to the VM. It's not uncommon to have multiple processes get spawned for each request that comes into a server and to end up having tens or hundreds of thousands of processes on a single VM at any given point. Edit: Geez, I even did a refresh check before clicking submit. I'm having the worst luck with that lately.
- rdtsc 12y agoIt was there to illustrate a point. And of course if you read the blog post you'd realize what an Erlang process is. It is like an OS process in that memory is not shared but it is only a few KB of memory overhead because it is also a lightweight thread. Yes, it sounds like it is magic, that it is not possible, but it is.
- jlouis 12y agoIndeed. There are better strategies for splitting up the work among several processes than to spawn a new one per element. While processes in BEAM are fairly cheap, they are not free. So I think your point is valid.