Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: A pair of "mathematical" attributes for arrays?

by TGI (Parson)
on Sep 10, 2007 at 16:33 UTC ( [id://638116]=note: print w/replies, xml ) Need Help??


in reply to A pair of "mathematical" attributes for arrays?

Interesting ideas. I think that instead of :zero, I'd like something more flexible:

my @foo :autovalue(0); my @bar :autovalue(23); print "$foo[3]\n"; # prints 0 print "$bar[3]\n"; # prints 23

Obviously a while (@bar) would run until all memory was exhausted, so care would need to be exercised with the use of this attribute.

I like the :nocirc suggestion, but the name doesn't make much sense to me. How about :posindex?

Update: Thanks to moritz for calling me on my lack of caffeine induced foolishness. Now, more awake, I stand by the rest of what I wrote.


TGI says moo

Replies are listed 'Best First'.
Re^2: A pair of "mathematical" attributes for arrays?
by moritz (Cardinal) on Sep 10, 2007 at 17:56 UTC
    Obviously a while (@bar) would run until all memory was exhausted

    Why should it? An empty array with non-zero default values would still be false, right?

      Oops. I somehow convinced myself that while works for array iteration something like it does with a filehandle.

      Array iterators (each, foreach, etc) should only deal with existing indexes. An empty array should be false.


      TGI says moo

Re^2: A pair of "mathematical" attributes for arrays?
by blazar (Canon) on Sep 12, 2007 at 07:45 UTC
    I like the :nocirc suggestion, but the name doesn't make much sense to me. How about :posindex?

    Well, I find it better than mine, but unsatisfactory too. I just couldn't concoct anything better: I wanted something short enough to be practical and I was thinking about "no circularity", but of course it's at best imprecise and more realistically patently wrong. OTOH yours gives me an impression of "positive indices only" which is not the case either. It's a matter of disabling a feature related to negative indices instead, for which I cannot think of a short enough description. But then you'll agree that it's a minor point anyway.

    Update: (just not to clutter the thread with yet another reply) yes, TGI, I like all of your suggestions. Of course they are all as far away from reality as a more thorough coverage and a better implementation of attributes and a wider adoption of them.

      My first though was along the lines of :nonegindex. But that's long and unwieldy. What about something with an argument:

      # $foo[-1] returns 'Illegal Array Index Error' @foo :negindex( value => 'Illegal Array Index Error' ); # $foo[-1] normal behavior @foo :negindex( REVERSE ); # $foo[-1] apply some filter ( filter takes array, index as args) @foo :negindex( filter => sub { return -1 * $_[0]->[ abs( $_[1]) ] } ) +; # $foo[-1] returns undef, exists( $foo[-1] ) is false. #@foo :negindex( DO_NOT_WANT ); @foo :negindex( NO_EXIST ); # And to anticipate all future feature creep: # $foo[-1] returns sends an email message @foo :negindex( email => bob@example.com );


      TGI says moo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://638116]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-24 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found