-
-
Save smls/0f1185c050467a9ffee9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
# Golfed-down demo for regex backtracking problem affecting http://rosettacode.org/wiki/Amb#Perl_6 | |
# and previously explored in https://gist.github.com/smls/85b78904e96eb589ea1e | |
# This works: | |
{ | |
'' ~~ m/ | |
:my ($a, $b); | |
[{ $a = 1 } || { $a = 0 }] | |
[{ $b = 0 } || { $b = 1 }] | |
<?{ all($a, $b) == 1 }> | |
{ say "$a $b" } | |
/; | |
} | |
say "---"; | |
# But this hangs indefinitely: | |
{ | |
'' ~~ m/ | |
:my ($a, $b); | |
<{ '[{ $a = 1 } || { $a = 0 }]' }> | |
<{ '[{ $b = 0 } || { $b = 1 }]' }> | |
<?{ all($a, $b) == 1 }> | |
{ say "$a $b" } | |
/; | |
} | |
# The only difference between the two is using: | |
# FOO -- literal sub-regex | |
# vs | |
# <{ 'FOO' }> -- eval'ed sub-regex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment