Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I was impressed by the brevity of the C solution using OpenMP (comment #81), especially compared to significantly more verbose Erlang and Haskell examples. I kept reading it, thinking, "Where's the fork?" and seeing nothing but a simple for...and then remembered that # is a preprocessor directive, rather than a comment, in C, and then googled for "parallel omp for". So, I actually learned something today from that ridiculous thread: http://en.wikipedia.org/wiki/OpenMP

Also, the Perl 6 one-liner is sort of laughably cute . I'm not sure I believe it would actually work, but if it does, the conciseness of Perl 6 is even higher than I'd realized; dropping about 9 words from the Perl 5 one-liner (which is already very small). But, I learned about the hyper operators in Perl 6, which is also cool: http://perl6advent.wordpress.com/2009/12/06/day-6-going-into...

In short, that was awesome reading over my morning tea.



There's a few short implementations of this algorithm on CodeGolf.SE: http://codegolf.stackexchange.com/questions/2722/implement-s...


I'm relieved to note that Haskell and Erlang don't have to be ridiculously verbose. There's even an Erlang one-liner that is competitive with the Perl and Ruby implementations for brevity. I was amused to note that Perl is still the shortest implementation, and could be shorter (though the frighteningly short Perl 6 implementation mentioned in the 4chan thread is either wrong, or the implementation of the <<. operator is still unfinished in Rakudo Star, because it does not actually do the job; I don't understand the hyperoperators well enough yet to know which is true).


significantly more verbose Erlang and Haskell examples

There are less verbose (but also less well-formed) solutions in these languages. Here's a working, hacky but still readable, 3-line one I just banged out for Erlang: http://pastebin.com/eZckJp9p


... and a version that trades a line for calling an actual function named sleep(), given there are rules to this silly game http://pastebin.com/heQ43K0E ...


Also, the Perl 6 one-liner is sort of laughably cute . I'm not sure I believe it would actually work

I don't think any current implementation supports auto-parallelization of hyperops. Regardless, hyper is really only spec'd to remove the result-ordering requirements so that it may optimize it (I wouldn't be surprised if was executed in chunks in slightly more sophisticated implementations.)


From my reading of the docs, it (>>.) doesn't seem to require parallelization in the implementation, at all...it just allows it and requires code to be parallel safe, but doesn't impose any parallel requirements on the Perl 6 implementation. So, something like that Perl one-liner that would require parallelism to even work at all simply isn't valid. It might be possible to build a Perl 6 that would exhibit the right behavior, but it would be unspecified behavior.

So, I think that tiny little implementation is bunk. I'd be curious to see what the actual smallest Perl 6 implementation would look like, or if it would be the smallest Perl 5 version except using "say" to shave off two characters.


(>>.) doesn't seem to require parallelization in the implementation, at all...it just allows it and requires code to be parallel safe

That's pretty much what I said.

I'd be curious to see what the actual smallest Perl 6 implementation would look like

If you want to guarantee it will work, then it will be about as long as a Perl 5 version. Every brief way to parallelize leaves a lot of the semantics up to the implementation. There's a good reason for that: this is a concurrent problem, but the hyperops are meant for parallelizable problems.


Yeah, I know, I was just working through it in my own head. Seeing it in the context of this "solution" to the sleep sort problem caused me to think hyper-ops were something they are not. So, I did a bunch of reading to figure out what they actually are. It took a while to wrap my head around it.

The side benefit is that it caused me to download a Perl 6 implementation for the first time since pugs many years ago. I probably won't be using it for anything other than tinkering, of course, but nothing wrong with playing with new things. And, YAPC is coming up, so I can hang out with the cool kids who are talking about Perl 6 and Rakudo.


Ah.

Perl 6 has been making strides lately. There's a bit of a refactor in the wings which should make it much more processor and memory efficient.

If it had the performance (and a package in Debian sources), I would be using it in production right now. Between grammars and the (clean!) syntax support for high order programming, it solves a lot of my headaches.


Oh hey, apparently the order of the results is maintained, according to Larry Wall. I'm not sure if that's new, or I misread something. (I was sure I read something about the result order being undefined.) So the tiny Perl 6 version does nothing at all for sorting per spec.




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

Search: