2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,18 +1,18 @@
|
|||
sub infix:<lf> ($a,$b) {
|
||||
next unless try $a.substr(*-1,1) eq $b.substr(0,1);
|
||||
"$a $b";
|
||||
#| an array of four words, that have more possible values.
|
||||
#| Normally we would want `any' to signify we want any of the values, but well negate later and thus we need `all'
|
||||
my @a =
|
||||
(all «the that a»),
|
||||
(all «frog elephant thing»),
|
||||
(all «walked treaded grows»),
|
||||
(all «slowly quickly»);
|
||||
|
||||
sub test (Str $l, Str $r) {
|
||||
$l.ends-with($r.substr(0,1))
|
||||
}
|
||||
|
||||
multi dethunk(Callable $x) { try take $x() }
|
||||
multi dethunk( Any $x) { take $x }
|
||||
|
||||
sub amb (*@c) { gather @c».&dethunk }
|
||||
|
||||
say first *, do
|
||||
amb(<the that a>, { die 'oops'}) Xlf
|
||||
amb('frog',{'elephant'},'thing') Xlf
|
||||
amb(<walked treaded grows>) Xlf
|
||||
amb { die 'poison dart' },
|
||||
{'slowly'},
|
||||
{'quickly'},
|
||||
{ die 'fire' };
|
||||
(sub ($w1, $w2, $w3, $w4){
|
||||
# return if the values are false
|
||||
return unless [and] test($w1, $w2), test($w2, $w3),test($w3, $w4);
|
||||
# say the results. If there is one more Container layer around them this doesn't work, this is why we need the arguments here.
|
||||
say "$w1 $w2 $w3 $w4"
|
||||
})(|@a); # supply the array as argumetns
|
||||
|
|
|
|||
|
|
@ -1,22 +1,18 @@
|
|||
sub amb($var,*@a) {
|
||||
"[{
|
||||
@a.pick(*).map: {"||\{ $var = '$_' }"}
|
||||
}]";
|
||||
sub infix:<lf> ($a,$b) {
|
||||
next unless try $a.substr(*-1,1) eq $b.substr(0,1);
|
||||
"$a $b";
|
||||
}
|
||||
|
||||
sub joins ($word1, $word2) {
|
||||
substr($word1,*-1,1) eq substr($word2,0,1)
|
||||
}
|
||||
multi dethunk(Callable $x) { try take $x() }
|
||||
multi dethunk( Any $x) { take $x }
|
||||
|
||||
'' ~~ 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 }>
|
||||
<{ amb '$d', <slowly quickly> }>
|
||||
<?{ joins $c, $d }>
|
||||
{ say "$a $b $c $d" }
|
||||
<!>
|
||||
/;
|
||||
sub amb (*@c) { gather @c».&dethunk }
|
||||
|
||||
say first *, do
|
||||
amb(<the that a>, { die 'oops'}) Xlf
|
||||
amb('frog',{'elephant'},'thing') Xlf
|
||||
amb(<walked treaded grows>) Xlf
|
||||
amb { die 'poison dart' },
|
||||
{'slowly'},
|
||||
{'quickly'},
|
||||
{ die 'fire' };
|
||||
|
|
|
|||
22
Task/Amb/Perl-6/amb-3.pl6
Normal file
22
Task/Amb/Perl-6/amb-3.pl6
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
sub amb($var,*@a) {
|
||||
"[{
|
||||
@a.pick(*).map: {"||\{ $var = '$_' }"}
|
||||
}]";
|
||||
}
|
||||
|
||||
sub joins ($word1, $word2) {
|
||||
substr($word1,*-1,1) eq substr($word2,0,1)
|
||||
}
|
||||
|
||||
'' ~~ 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 }>
|
||||
<{ amb '$d', <slowly quickly> }>
|
||||
<?{ joins $c, $d }>
|
||||
{ say "$a $b $c $d" }
|
||||
<!>
|
||||
/;
|
||||
Loading…
Add table
Add a link
Reference in a new issue