develooper Front page | perl.perl6.compiler | Postings from July 2008

[perl #56612] [BUG] Closures are broken.

From:
Vasily Chekalkin
Date:
July 5, 2008 09:13
Subject:
[perl #56612] [BUG] Closures are broken.
# New Ticket Created by  Vasily Chekalkin 
# Please include the string:  [perl #56612]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56612 >


Hello.

Simple test case for closures shows accessing wrong lexpad.

sub times($a,$b) {
     $a * $b;
};

sub divide($a,$b) {
     $a / $b;
}

sub make_op($op) {
     sub($a,$b) { $op($a,$b) }
};

my $t = make_op(&times);
say $t(21,2);

my $div = make_op(&divide);
say $div(42,2);

# expected result is
# 42
# 21
#
# actual is
# 42
# 84

-- 
Bacek



Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About