Re: McNamara's C$# as a property of any array element
[Apologies for the late reply. Still catching up] On Thu, 17 Aug 2000 20:51:01 -0500, David L. Nicol said: What if its a method of anything in an array? $_ is already a reference to the object on the array in for loops rather than a copy of it. What if we make change be not something about for loops, but about anything in an array? print "The index, in its array, of $_ is $CORE::ARRAY_INDEX{$_}" where %CORE::ARRAY_INDEX is a very magical system-provided hash that tells us the index in its array of something that is in an array. It is often undefined; and would get tricky but definable for objects that can be in multiple containers at once, I'd think it would be the index of the item in the most recent container it was accessed from. If we are going to have arrays that can be sparse, we've pretty much got to keep track of this info somehow anyway, so might as well give a way to access it. What's wrong with defining each() on arrays? while(my($i,$v)=each @array){ print "Element at $i is $v\n"; } Then if you have a sparse array, you only get the defined elements, otherwise you get all of them. Whether for iterates over the defined elements of a sparse array, or all of them is another question. If that gets optimized into an iterator, you're only likely to get the defined elements, because that'll probably use the same mechanism as each(). I suppose there could be two mechanisms, then implementors could choose whether to make them do the same or different things. Otherwise, there should be some way of specifying that you want all elements (or only defined, whatever the default isn't) when creating an iterator or using a for loop on an array. # This is the easy bit my $iter1=$array-iter_all; my $iter2=$array-iter_def; my $iter3=$array-iter; # Default to iter_def ? # This isn't for(@$array){} # default iterator for($array-iter_all){} # Change for to call iterators? for($array-iter_def){} I suppose this also gives you the choice with each(): while(my($i,$v)=each @$array){} # Default iterator while(my($i,$v)=each $array-iter_all){} # All elements while(my($i,$v)=each $array-iter_def){} # Defined elements This is looking like for/each should act on iterators "natively", and create an iterator if given a list/hash.
Re: McNamara's C$# as a property of any array element
On Fri, Aug 18, 2000 at 03:46:10AM -0500, David L. Nicol wrote: Mike Pastore wrote: Any thoughts on this? Yes, please, the idea, that is: I've wanted such a variable oftentimes. What I'm not certain about is reusing the $#. Reusing obsoleted stuff is Dangerous. Attributes. ($item : arrayposition) would tell us what the position is. Kinda oversteps my taste of verbosity. -- $jhi++; # http://www.iki.fi/jhi/ # There is this special biologist word we use for 'stable'. # It is 'dead'. -- Jack Cohen
Re: McNamara's C$# as a property of any array element
"David L. Nicol" wrote: What if its a method of anything in an array? $_ is already a reference to the object on the array in for loops rather than a copy of it. What if we make change be not something about for loops, but about anything in an array? print "The index, in its array, of $_ is $CORE::ARRAY_INDEX{$_}" where %CORE::ARRAY_INDEX is a very magical system-provided hash that tells us the index in its array of something that is in an array. It is often undefined; and would get tricky but definable for objects that can be in multiple containers at once, I'd think it would be the index of the item in the most recent container it was accessed from. If we are going to have arrays that can be sparse, we've pretty much got to keep track of this info somehow anyway, so might as well give a way to access it. I sent John an email with a suggestion of modifying Cpos() or a similar function (because pos() already has a very different meaning) to do this for us, as C$# already has meaning with regards to arrays. More specifically: @foo = qw(sun moon stars rain); @bar = qw(earth water fire wind); foreach $thingy (@foo) { foreach $whutzit (@bar) { print "Thingy: ", $thingy, " at ", pos(@foo), "\n"; print "Whutzit: ", $whutzit, " at ", pos(@bar), "\n"; } } Actually, now that I'm thinking about it, I like your idea more, but I think we need more. :) I'd like to see a special 'hash' or array properties that tell us 1) the first index, 2) the "current" index, 3) the last index, 4) maybe others? $#ARY could be depreciated (another "confusing" special variable bites the dust) and we would have a whole lot more detail regarding arrays during array ops. Any thoughts on this? -- Mike Pastore [EMAIL PROTECTED]