# New Ticket Created by  "Carl Mäsak" 
# Please include the string:  [perl #77474]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=77474 >


<TimToady> I think I've found a binding bug.  http://wall.org/~larry/hamming.p6

#!/usr/local/bin/perl6

#hamming = 1 : map (2*) hamming `merge` map (3*) hamming `merge` map
(5*) hamming
#     where merge (x:xs) (y:ys)
#            | x < y = x : xs `merge` (y:ys)
#            | x > y = y : (x:xs) `merge` ys
#            | otherwise = x : xs `merge` ys

sub infix:<merge> (@x [$x, *...@xtail], @y [$y,*...@ytail]) {
    if    $x < $y { $x, (@xtail merge @y) }
    elsif $x > $y { $y, (@x merge @ytail) }
    else          { $x, (@xtail merge @ytail) }
}

my @hamming := (1, (@hamming X* 2) merge (@hamming X* 3) merge (@hamming X* 5));

say ~...@hamming[^20];

<masak> ooh, the Hamming sequence!
<TimToady> I would guess that the *...@xtail is not successful in binding
to the conjectural part of the @hamming array
<masak> TimToady: any reason why it shouldn't bind?
<TimToady> rakudo: sub foo (@x [$xhead, *...@xtail]) { say ~...@xtail };
foo([1,2,3]) [21:33]
<p6eval> rakudo 18189a: OUTPUT«2 3␤»
<masak> \o/
<Tene> perl6: my @x = 1..5; sub foo(@a [$a, *...@atail]) { say "head:
$a\ntail: {[email protected]}"; }; foo(@x);
<p6eval> rakudo 18189a: OUTPUT«head: 1␤tail: [2, 3, 4, 5]␤»
<TimToady> rakudo: sub foo (@x [$xhead, *...@xtail]) { say ~...@xtail };
foo([1, (2...3)])
<p6eval> rakudo 18189a: OUTPUT«2 3␤»
<TimToady> rakudo: sub foo (@x [$xhead, *...@xtail]) { say ~...@xtail[^3] };
foo([1, 'x' xx *])
<p6eval> rakudo 18189a: OUTPUT«(timeout)»
<TimToady> anyway, hamming is sort of an acid test for laziness, the
way man-or-boy is for scoping
<TimToady> and currently we flunk...
<pmichaud> file a bug report for hamming, please.  I know enough of
the binding codenow that I think I might be able to fix it up.
<pmichaud> I'd like to see that one work.
* masak submits rakudobug for hamming

Reply via email to