On Thu, 4 Mar 2004 [EMAIL PROTECTED] wrote:

> Accepting 'undef' in a map operation is ok, but a Set cannot contain
> 'undef' !

The problem is that if the callback is called in a scalar context, and it
does a bare return, like this:

 $set->iterate( sub { return } )

then that "return" returns an undef.  In fact, I think you don't even need
a bare return.  Simply following off the end of the subroutine would do
the trick:

 sub foo { if ( $_[0] > $x ) { ... } }

so if \&foo were the callback, and the argument wasn't greater than $x,
then it would return undef!

> So we only have two options if we get an undef:  to die, or to discard
> the value.

I think we need to die and provide a different way to remove elements,
probably a separate method.

> > just to avoid the effect.  I think if you want to be able to modify
> > the set, you should provide different methods for that.  ->map and
> > ->grep come to mind.
>
> People are already confused with lists vs. sets.
>
> I think using map and grep would lead them to think sets _are_ lists.

True, but the map/grep analogue would make the functionality obvious.  How
about set_grep() and set_map()?


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

Reply via email to