3 # This is just a hand-written lazy attribute grammar to help
4 # me decide if I want to port L::AG to Perl 6 (i.e. whether
5 # pugs is going to give me too much bullshit like it did
6 # last time I tried to port an object-oriented module).
7 # So far, it looks pretty good.
14 return $.value
= $thunk();
26 return Thunk
.new
(code
=> &code
);
30 method visit
($parent) {
32 min
=> thunk
{ $.value
},
33 result
=> thunk
{ Leaf
.new
(value
=> $compute<gmin
>.call
) },
34 gmin
=> thunk
{ $parent<gmin
>.call
},
43 method visit
($parent) {
46 min
=> thunk
{ min
($lvis<min
>.call
, $rvis<min
>.call
) },
47 result
=> thunk
{ Branch
.new
(left
=> $lvis<result
>.call
, right
=> $rvis<result
>.call
) },
48 gmin
=> thunk
{ $parent<gmin
>.call
},
50 ($lvis, $rvis) = ($.left
.visit
($compute), $.right
.visit
($compute));
59 method visit
($parent) {
62 result
=> thunk
{ $tvis<result
>.call
},
63 gmin
=> thunk
{ $tvis<min
>.call
},
65 $tvis = $.tree
.visit
($compute);
74 left
=> Leaf
.new
(value
=> 1),
77 left
=> Leaf
.new
(value
=> 2),
78 right
=> Leaf
.new
(value
=> 3),
80 right
=> Leaf
.new
(value
=> -3),
86 say $tree.visit
( {} ).<result
>.call
.perl
;