Re: RFC 262 (v1) Index Attribute
John Porter wrote: > > David L. Nicol wrote: > > > > > > print "Found It at position ${_:n}!\n" if /$seek/ foreach @items > > If we are going to be throwing around attributes like that, why > don't we switch to using the ubiquitously recognizable dot instead > of colon? > > for my $iter ( @things ) { > print "index= ", $iter.indexof, "\n"; I hope that was a rhetorical question, but here is the rhetorical answer: Because the ubiquitously recognizable dot is already in use as the string concat operator in this language, and overloading it would cause far far far too much ambiguity. This answer also goes for schemes for optimising -> into one character.
Re: RFC 262 (v1) Index Attribute
David L. Nicol wrote: > > > print "Found It at position ${_:n}!\n" if /$seek/ foreach @items If we are going to be throwing around attributes like that, why don't we switch to using the ubiquitously recognizable dot instead of colon? for my $iter ( @things ) { print "index= ", $iter.indexof, "\n"; -- John Porter Jetzt schalten wir das Radio an. Aus dem Lautsprecher klingt es dann...
Re: RFC 262 (v1) Index Attribute
Webmaster wrote: > > (I have attached a prototype of what I had in mind) > > From: "David L. Nicol" <[EMAIL PROTECTED]> > > Yes, that is exactly what is being suggested, but the "indexof" function > > is implicit in the attribute. Your code becomes > > > > print "Found It at position ${_:n}!\n" if /$seek/ foreach @items > > I do like the iterator, but I also prefer: > " split( /$delim/, $items[$index] );" > To > " split( /$delim/, $items[${_:n}]);" > for readability. yes. I imagine :n would be used in debugging code, where you don't really need it for the general meaning of the passage. $items[$_:n]# curlies only are required for interpolation I didn't say it so many words, but an example of how to _access_ an attribute inside interpolation -- that is what I was getting at too; > The two might actually be able to work together, if ':n' > was an element of the actual array, whereby a subsequent call to the array > index function using 'null' or 'undef' as the starting index would pick up > where it left off. The other part is that the array index function could > potentially return a list. (see attached) > > It's only a suggestion, and I have programmed long enough to do it other > ways (see attached), but if RFC 199 doesn't fly, this would be nice to have > around. > Grant M. > [EMAIL PROTECTED] it's not a member, but an attribute, thus the colon. The curlies are only needed because we're inside double-quotes in my example.
Re: RFC 262 (v1) Index Attribute
Webmaster wrote: > What would really be nice here is an C function, similar to the > scalar version, that returns the index of the matching entry in a list. For > instance: > > my $n=0; > foreach (@items){ > print "Found It at position $n!\n" if /$seek/; > $n++; > } > Could be replaced by: > if (my $n = arrindex( @items, $seek )) { > print "Found It at position $n!\n" ; > } > Grant M. > [EMAIL PROTECTED] Yes, that is exactly what is being suggested, but the "indexof" function is implicit in the attribute. Your code becomes print "Found It at position ${_:n}!\n" if /$seek/ foreach @items -- David Nicol 816.235.1187 [EMAIL PROTECTED] "A taste so good that we stand behind every bottle and can."
Re: RFC 262 (v1) Index Attribute
On Wed, Sep 20, 2000 at 09:03:39AM -0400, Webmaster wrote: > Graham Barr Wrote: > >Well if there ever is a way to shortcut grep this could be genera;ized > >to > > > > my $index = grep { break if $_ eq $seek; 1 } @items; > > Wouldn't this also assume that grep return the number of times the block was > NOT true, But in that example the block is always true, thats what the 1 is for. Graham.
Re: RFC 262 (v1) Index Attribute
Graham Barr Wrote: >Well if there ever is a way to shortcut grep this could be genera;ized >to > > my $index = grep { break if $_ eq $seek; 1 } @items; Wouldn't this also assume that grep return the number of times the block was NOT true, rather than it's current implementation of the number of times it IS true? I think that in the example, grep would simply return either '1' or '0', unless there was some easy way to say: my $index = grep { while( $_ ne $seek) } @items; I might be wrong here, though. It's still early. Grant M. [EMAIL PROTECTED]
Re: RFC 262 (v1) Index Attribute
On Wed, Sep 20, 2000 at 08:05:20AM -0400, Webmaster wrote: > David Nicol Wrote in RFC 262: > >foreach $item (@items){ > >#print "$item was at location ",$item:n,"\n"; > >print "$item was at location ${item:n}\n"; > >}; > > What would really be nice here is an C function, similar to the > scalar version, that returns the index of the matching entry in a list. For > instance: > > my $n=0; > foreach (@items){ > print "Found It at position $n!\n" if /$seek/; > $n++; > } > Could be replaced by: > if (my $n = arrindex( @items, $seek )) { > print "Found It at position $n!\n" ; > } Well if there ever is a way to shortcut grep this could be genera;ized to my $index = grep { break if $_ eq $seek; 1 } @items; assuming `break' causes the shortcut An therefore allowing more comparisons than just eq Graham.
Re: RFC 262 (v1) Index Attribute
David Nicol Wrote in RFC 262: >foreach $item (@items){ >#print "$item was at location ",$item:n,"\n"; >print "$item was at location ${item:n}\n"; >}; What would really be nice here is an C function, similar to the scalar version, that returns the index of the matching entry in a list. For instance: my $n=0; foreach (@items){ print "Found It at position $n!\n" if /$seek/; $n++; } Could be replaced by: if (my $n = arrindex( @items, $seek )) { print "Found It at position $n!\n" ; } Grant M. [EMAIL PROTECTED]