Skip to content

Instantly share code, notes, and snippets.

@smls
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smls/0f1185c050467a9ffee9 to your computer and use it in GitHub Desktop.
Save smls/0f1185c050467a9ffee9 to your computer and use it in GitHub Desktop.
#!/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