Welcome to the Monastery  
PerlMonks 
A pair of "mathematical" attributes for arrays?by blazar (Canon) 
on Sep 10, 2007 at 09:56 UTC ( #638020=perlmeditation: print w/replies, xml )  Need Help?? 
There have been some posts lately, inspired by Project Euler's problems. I also play with PE, although on a sparse basis and having joined much late. In a particular problem it turned out to be of much use Perl's ability to return undef when accessing an array element beyond its actual length, and the promotion of undef to zero in a numeric addition. Except that it triggers the well know warning, in which case the usual cure is to locally disable it. (Since the actual script body was 14 lines, I eventually committed for once the sin of commenting out the use warnings; line altogether.) Of course I may have used a (IMHO) visually obtrusive 0 instead... The point is, in this case the intended usage is more in line with common mathematical one, especially as in combinatorics. As an example consider the following minimal implementation of a program to print the first ten rows of Pascal's triangle:
If I enable warnings I'll get two for the comparison for the first two iterations and one for the addition per each row. So I wonder if one day a predefined attribute may be specified on an array so that accessing it beyond its limits would return 0 rather than undef. Perhaps something like
Also, Perl's current behaviour with negative indices is occasionally practical but also not best suited for some mathematicallike usages. So still in the brainstorming vein as above, perhaps another attribute should exist, say :nocirc, to the effect of returning undef (or 0 if in conjunction with :zero) when accessing negative indices. Thus the code above may become the clearer  for the mathematically inclined:
Admittedly, this is not Perl's everyday job. Still it may be useful. I would add this to ysth's 5.12 wishlist.
Back to
Meditations

