Skip Menu |

This queue is for tickets about the Want CPAN distribution.

Report information
The Basics
Id: 26928
Status: resolved
Priority: 0/
Queue: Want

People
Owner: Nobody in particular
Requestors: ss [...] smartech.pf
Cc:
AdminCc:

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



Subject: Module Want 0.12
Date: Thu, 03 May 2007 23:00:03 -1000
To: bug-Want [...] rt.cpan.org
From: ss [...] smartech.pf
Hi there, I would like to report a behavior of the function howmany() in package Want-012 that does not seem to be in sync with the associated documentation. I'm using : - Perl v5.8.7 built for i386-linux - Linux xxx 2.6.16.4 #1 PREEMPT Mon Apr 17 15:12:40 TAHT 2006 i686 AMD Athlon(TM) XP 2800+ unknown GNU/Linux, based on Mandriva 2006. _Beginning of (simplified) code_ #! /usr/bin/perl use strict; use warnings; use Want qw( howmany ); sub cx_iterator { my $iterator = shift; return sub { my $context = wantarray(); / # Return nothing in void context/ return unless defined $context; / # Return 1 result in scalar context/ return $iterator->() unless $context; # List context : how many results are requested ? my $want = howmany() ; # We expect that calls like # () = $cx_iterator->(); or @l = $cx_iterator->() # make howmany() return 'undef' as said in the documentation # so to know when a call wants an 'infinity' of values. if ( ! defined $want ) { ... } else { map { $iterator->() } 1 .. $want; } } } # Main my $cx_iterator = cx_iterator( $an_iterator ); # Void context => OK $cx_iterator->(); # Scalar context => OK $x = $cx_iterator->(); # Finite List context => OK ($x) = $cx_iterator->(); print "Got(1): $x\n"; ($x, $y, $z) = $cx_iterator->(); # Infinite list context => KO # Always return 1 value () = $cx_iterator->(); @l = $cx_iterator->(); _End of code_ In my experience, the problem lies with "Infinite list context", for which howmany() always returns the value 1, not in sync with the documentation that says that in this context howmany() should return the Perl value 'undef'. So I looked and tracked down some part of Want code, which shows that indeed, howmany() has the provision for dealing with negative counts : sub howmany () { my $level = bump_level(@_, 1); my $count = want_count($level); return ($count < 0 ? undef : $count); } In infinite list context (in my experience), want_count() always returns the value 1, which in turn becomes the return value of howmany(). Of course, I expected want_count() to return a negative value. Am I doing something the wrong way ? Or is there a problem with my environment ? Or is this a problem with the low level want_count() function in infinite list context ? At this point, I have not read the C code, and I'm not sure I'm properly diagnosis the problem, at most one side effect of it. Thank you for your attention to this matter. Franck PORCHER -- Franck Porcher, Docteur ès Sciences (Paris VI), Informatique théorique ---------------------------------------------------------------------- SMART Technologies Les solutions intelligentes Service et Ingénierie Informatique Solutions Open Source Linux 1995-2007 : Premier fournisseur en Polynésie française Tél: (689) 550 815 Vini: (689) 711 911 Email: fporcher@smartech.pf Web: www.smartech.pf ---------------------------------------------------------------------- "You can analyze the past but you have to design the future."
Fixed in 0.14