Hacker News new | comments | show | ask | jobs | submit login

I like concurrency in Rakudo Perl 6. (https://docs.perl6.org/language/concurrency)

Especially the .hyper method that turns a regular sequence into hyper sequence that gets processed in parallel. First 5000 prime numbers:

    # single-thread, takes 14.893s
    put ^∞ .grep(*.is-prime).head: 5000

    # multi-threaded, takes 8.853s on my 2-core box
    put ^∞ .hyper.grep(*.is-prime).head: 5000

Concurrency isn't the same thing as parallelism. You can have concurrency without ever executing two things at the same time. You just give some CPU cycles to one threaad, then pause it, give cycles to the other thread, and keep switching back and forth. Indeed, this is what any multitasking operating system has always done, even when every computer only had one CPU.

For parallelism as what you describe, D instead has approximately the same thing. There's a `parallel` function in the standard library that works on any range (i.e. any iterable). You basically instead of doing

   foreach(object; somerange) {
      // ..

   foreach(object; parallel(somerange)) {
      // ...
and it works like your Perl example.

If you want it more functionalish, without writing out the loop, you can use `taskPool.map` instead of ordinary `map` for the same effect. More details:

stdlib: https://dlang.org/phobos/std_parallelism.html

Programming in D chapter on parallelism: http://ddili.org/ders/d.en/parallelism.html

Is this more than just flat data parallelism, in any way? Honest question!

Concurrency is not a first class citizen in Perl 6 though. As with Perl 5 the best you can hope for is actor model implemented on top of promises/futures.

What would make it a first-class citizen?

Even an empty Rakudo Perl 6 program is a multi-threaded program, as the dynamic optimizer runs on a separate thread. I'd figure if that's possible, concurrency/parallelism would be quite a first-class citizen, not a best hope on top of something.

Language support for actor model as opposed to shared memory multithreading would make concurrency a first class citizen.


Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact