logo       

Re: On the range operator: msg#00005

Subject: Re: On the range operator
The problem I have with each is the "while" loop feels counterintuitive to what
you're trying to do.  IIRC, in Perl 6 there will be a .kv() method on both
hashes and arrays, returning a (lazy) list of keys and values interspersed (or
maybe key value pairs...hmmm).

    for %hash.kv -> $k, $v {
        # ...
    }

    for @array.kv -> $idx, $elt {
        # ...
    }

On Wed, 2 Jul 2003, Xavier Noria wrote:

> Thinking about the convenience of the current behaviour of the range
> operator as a way to easily iterate through an array when one needs
> both the index and the element, as some have stated, I wonder whether
> the lack of a specific idiom for this as Ruby has is on purpose.
>
> For instance, we could have:
>
>     foreach_with_idx my ($idx, $elt) (@array) {
>         # ...
>     }
>
> I don't like that very much indeed. If it was kind of a foreach it
> should IMHO resemble it as much as possible, but I don't imagine a
> suitable special variable for the index in
>
>     foreach_with_idx (@array) {
>         # where would the index be stored?
>     }
>
> and the use as a modifier is not clear as well.
>
> The parallelism with each() for hashes is however so clear to me that if
> I could I would probably suggest
>
>     while (my ($idx, $elt) = each @array) {
>         # ...
>     }
>
> Does that each() have been discussed and discarded previously? Do you
> see any drawbacks to it?
>
> fxn
>

-- 
Adam Lopresto
http://cec.wustl.edu/~adam/

I don't want to achieve immortality through my work.  I want to achieve
immortality through not dying.
                -- Woody Allen



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe