in reply to What does it mean that a "pattern cannot be reversed?"

To answer your questions in reverse order: yes, yes, and a non-reversible pattern would be one with strange side effects, or one that calls out to a subrule that can't be reversed. Most ordinary patterns can be reversed, and of course all constant patterns can be reversed. It's not so obvious that you can look for .*? and such in reverse, but you can.

The only alternative is to reparse the string from the beginning (or from somewhere earlier in the string) and see if you happen to come out to the same place. This strikes me like one of those super-inefficient sorting algorithms where you shuffle the elements into a random order and then check to see if you happened to get them in order this time. If not, try a different guess. The intent of the verbiage in the synopsis is to rule out such a guessing implementation, which people tend to fall into because the notion of reversing the syntax tree is rather exotic until you think about it a while. But tree reversal is the right way to do it in a backtracking rule engine, so that's how Perl 6 will do it.

Replies are listed 'Best First'.
Re^2: What does it mean that a "pattern cannot be reversed?"
by tphyahoo (Vicar) on Jan 07, 2005 at 13:28 UTC
    Thanks...

    What would be interesting, if anybody is up for it, is an actual concrete example of a nonreversible patttern, in either perl5 or perl6 syntax (or both).

    (?<=(a|aa))
    is not permitted in perl5, because it is a variable length lookbehind. Glad to hear we get these in perl6.

    Could someone throw out an example of what we can't do in perl6?

    Maybe this is academic, but I like knowing the limits of pattern matching, as well as its power.

    UPDATE: this seems to have just been answered, or at least a good attempt was made, by hv below, who must have been posting same time I was.