On Wednesday 14 July 2004 08:39, David Storrs wrote:
> > To repeat Dave and myself - if
> >     @x = 1 .. Inf;
> > then
> >     rand(@x)
> > should be Inf, and so
> >     print $x[rand(@x)];
> > should give Inf, as the infinite element of @x is Inf.

Please take my words as my understanding, ie. with no connection to mathmatics 
or number theory or whatever. I'll just say what I believe is practical.

> Does it even make sense to take the Infiniteth element of an
> array?...after all, array indices are integers, and Inf is not an
> integer.  
I'd believe that infinity can be integer, ie. has no numbers after the comma; 
and infinity is in the natural numbers (?), which are a subset of integers.

> If we allow it, should we also allow people to take the 
> NaNth element of an array?  
NaN is already a "number" (internal representation), so it doesn't get 
converted.
As there is no NaNth element, it would return either undef (as in (0,1,2)[8] ) 
or an exception, as it is no numeric index.

> How about the 'foobar'th element? 
'foobar' is converted to a number, so the 0th element is taken.

> What happens if I take the Infiniteth element of a finite list?
undef, as in 8th element of (1,2,3).

> I think I would prefer if using Inf as an array index resulted in a
> trappable error.
That's a possibility. It could raise an exception as with NaN.

To summarize:
        @x= ('a', 5 .. Inf, 'b');
        $x[0] is 'a'
        $x['foo'] is 'a'
        $x[-1] is 'b'
        $x[2] is 6
        $x[2002] is 2006
I believe these are clear and understandable.

        $x[Inf] is 'b'
        $x[-2] is Inf
        $x[-10] is Inf
        $x[-2] is Inf
These would result in simply interpolating the indizes.

        $x[NaN] gets an exception
because NaN is already of numeric type (as in $x=tan(pi/2)), but can not be 
associated to any index.


So I'd propose to solve this argument based on "can be used as an index".
An infinite array (and even an finite) can be asked for an infinite index - 
which has an value for infinite arrays.
This is just so there's no special coding for some indizes necessary - imagine 
a lookup like
        @x = (10,9,9,8,8,8,6,3,2,1,1,1,1,0);
        $number = scalar(<STDIN>)+0;
        print $x[10/$number];
which would work for *any* input, and just give undef for most of them.


Regards,

Phil


BTW: is it possible to define a look-up table as in
        @x = (1, 2, 3, 4, 5, Inf .. Inf)
to get everything from [5] on to be Inf?

Reply via email to