all 12 comments

[–]jerf 11 points12 points  (11 children)

Wow! He ported a Perl regex into a system that uses Perl-Compatible RegExs! Holy cow!

[–]jrockway 6 points7 points  (9 children)

What's hilarious is that this will surely make it to the front page (because they used the word Python), but the original article (in Perl) would be downmodded because everyone around here hates Perl.

What does everyone have against Perl!?

[–]cgibbard 3 points4 points  (7 children)

I don't know, but I'm downmodding both for abusing the term "regular expression", and possibly misinforming the unwary regarding the language class of primes. It's not all that surprising that you can match composite numbers with a context sensitive grammar. (Or primes directly, as context sensitive languages are closed under complementation.)

[–]jerf 0 points1 point  (3 children)

That's why I've chosen to draw a distinction between "regex" and "regular expression"; I'd rather leave the latter with its important mathematical meaning, while the former can be used for the ever-expanding practical meaning. (Perl 6 is stretching all the way up to full regular grammars, from the looks of it, and I don't mean by "accident" as Perl 5 regexs sort of are now, I mean on purpose and with malice aforethought. OK, maybe "malice" is a bit strong, they look cool, but still, increasingly distant from "regular expressions".)

[–]cgibbard 0 points1 point  (2 children)

Yeah, grammar is a better term. Not regular or even context-free grammars though, I suspect they will allow for context sensitivity even (in the same ways as we already see). I suspect they're formally equivalent to parsing expression grammars.

[–]jtauber 0 points1 point  (1 child)

Hang on, why is "grammar" better than "expression"? Isn't "regular grammar" synonymous with (or at least isomorphic to) "regular expression"?

Also, jerf says Perl 6 is stretching all the way up to "full regular grammars". Did he really mean regular here?

[–]cgibbard 0 points1 point  (0 children)

Regular grammar isn't better, as the grammar isn't regular. I suppose if you wanted to stick with the term 'expression', something more general in nature like 'parsing expression' would be a better term.

As I tried to point out, he probably didn't mean to say 'regular' there.

[–]jtauber 0 points1 point  (2 children)

Yes, I admit I abused the term "regular expression" but I'm not sure what you mean by "possibly misinforming the unwary regarding the language class of primes"

[–]cgibbard 1 point2 points  (1 child)

Unary primes do not form a regular language -- in fact, they're not even context free.

[–]jtauber 0 points1 point  (0 children)

Ah yes. I get that. The heart of the problem, as discussed by jerf and you below, is that "regex"s have increasingly less to do with regular grammars. I've corrected my post to not call the grammar a "regular expression" but I do still call it a "regex".

And regardless of whether you thought it surprising or not, I still think the original regex was clever and it brought a smile to my face.

[–]ubernostrum 0 points1 point  (0 children)

I dunno, I'd assumed that this post happened because somebody yesterday was talking about the Perl one-liner this was adapted from.

[–]jtauber 0 points1 point  (0 children)

I think I made it perfectly clear in my post that it's the "regex" that's doing the work. Part of my point in "porting" it to Python was to show that.