Skip Menu |

This queue is for tickets about the Language-Functional CPAN distribution.

Report information
The Basics
Id: 20698
Status: resolved
Priority: 0/
Queue: Language-Functional

People
Owner: Nobody in particular
Requestors: dcantrell [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.03
Fixed in: (no value)



Subject: Test failures
Tests 79 and 81 fail when using perl 5.8.8: not ok 79 # Test 79 got: <UNDEF> (test.pl at line 89) # Expected: "1" # test.pl line 89 is: ok(eval {show(any { even(shift) } integers)}, '1'); # 79 ok 80 not ok 81 # Test 81 got: <UNDEF> (test.pl at line 91) # Expected: "0" # test.pl line 91 is: ok(eval {show(all(\&odd, integers))}, '0'); # 81
From: ppisar [...] redhat.com
Dne St 26.čec.2006 11:25:03, DCANTRELL napsal(a): Show quoted text
> Tests 79 and 81 fail when using perl 5.8.8: > > not ok 79 > # Test 79 got: <UNDEF> (test.pl at line 89) > # Expected: "1" > # test.pl line 89 is: ok(eval {show(any { even(shift) } integers)}, > '1'); # 79 > ok 80 > not ok 81 > # Test 81 got: <UNDEF> (test.pl at line 91) > # Expected: "0" > # test.pl line 91 is: ok(eval {show(all(\&odd, integers))}, '0'); # 81
This is because `all' and `any' does: sub any(&$) { my($p, $xs) = @_; map { return 1 if $p->($_); } @{$xs}; return 0; } And the the last argument of `map' expands to infinite list which causes to confess on line 1689 in FETCH().
From: ppisar [...] redhat.com
I changes any() and all() implementation to pass tests. Not sure if this what author intended because there are following tests contradicting the short-circuiting advertised on POD: ok(eval {show(all(\&odd, integers))}, '0'); # 81 ok(eval {show(all {1} integers)}, undef); # 82 (fails!) According test 81 all() must check elements of infinite list and not to confess. According test 81 all() must recognize the check never ends and confess. So in worst case, all() must check all members with index < INFINITE and confess after that.
Subject: perl-Language-Functional-0.04-Fix-any-and-all-on-infinite-list.patch
From 73c916ba63070d9076b1286220ea7544d24925bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com> Date: Tue, 14 Jun 2011 18:19:25 +0200 Subject: [PATCH] Fix any() and all() on infinite list --- Functional.pm | 31 ++++++++++++++++++++++++------- 1 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Functional.pm b/Functional.pm index 78cfadd..493979c 100644 --- a/Functional.pm +++ b/Functional.pm @@ -1320,9 +1320,18 @@ In Haskell: sub any(&$) { my($p, $xs) = @_; - map { - return 1 if $p->($_); - } @{$xs}; + my $n = 0; + my $size = $#{$xs}; + while ($n <= $size) { + return 1 if $p->($xs->[$n]); + $n++; + } + if ($size == $Language::Functional::INFINITE + or $size == $Language::Functional::INFINITE - 1 + ) { + confess "Evaluating predicate on inifinite number of elements " . + "would never end!"; + } return 0; } @@ -1345,10 +1354,18 @@ In Haskell: sub all(&$) { my($p, $xs) = @_; - map { - my $x = $_; - return 0 if not $p->($x); - } @{$xs}; + my $n = 0; + my $size = $#{$xs}; + while ($n <= $size) { + return 0 if not $p->($xs->[$n]); + $n++; + } + if ($size == $Language::Functional::INFINITE + or $size == $Language::Functional::INFINITE - 1 + ) { + confess "Evaluating predicate on inifinite number of elements " . + "would never end!"; + } return 1; } -- 1.7.5.4
Thanks, released as 0.05. The infinite list is a bit of a hack.