Skip to content

Instantly share code, notes, and snippets.

@smls

smls/01_amb.p6 Secret

Last active August 6, 2016 07:59
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/407f65d275810f41014b522148f2312a to your computer and use it in GitHub Desktop.
Save smls/407f65d275810f41014b522148f2312a to your computer and use it in GitHub Desktop.
use MONKEY-SEE-NO-EVAL;
sub amb ($var, *@a) {
my $r = # DEBUG
"[" ~ ("|| \{ $var = '$_' }" for @a) ~ "]";
say "\n$r"; # DEBUG
$r # DEBUG
}
sub joins ($word1, $word2) {
my $r = # DEBUG
substr($word1,*-1,1) eq substr($word2,0,1);
say "{$r ?? "✓" !! "✕"} $word1:$word2"; # DEBUG
$r # DEBUG
}
'' ~~ m/
:my ($a, $b, $c, $d);
<{ amb '$a', <the that a> }>
<{ amb '$b', <frog elephant thing> }>
<?{ joins $a, $b }>
<{ amb '$c', <walked treaded grows> }>
<?{ joins $b, $c }>
{ say "$a $b $c" }
<{ amb '$d', <slowly quickly> }>
<?{ joins $c, $d }>
{ say "$a $b $c $d" }
<!>
/;
[|| { $a = 'the' } || { $a = 'that' } || { $a = 'a' }]
[|| { $b = 'frog' } || { $b = 'elephant' } || { $b = 'thing' }]
✕ the:frog
✓ the:elephant
[|| { $c = 'walked' } || { $c = 'treaded' } || { $c = 'grows' }]
✕ elephant:walked
✓ elephant:treaded
the elephant treaded
[|| { $d = 'slowly' } || { $d = 'quickly' }]
✕ treaded:slowly
✕ treaded:quickly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment