----- Original Message ----- From: James Mastros <[EMAIL PROTECTED]> Date: Sunday, July 18, 2004 5:03 am Subject: xx and re-running
> Recently on perlmonks, at > http://perlmonks.org/index.pl?node_id=375255, > someone (DWS, actually) brought up the common error of expecting x > (in > particular, listy x, which is xx in perl6) to not create aliases. > What > he was doing in particular, I don't have any expectation of making > it > work, but what about the also-common problem of C< @randoms = (int > rand > 100) xx 100 >? In perl5, this picks one random integer between 0 > and > 99, and copies it 100 times -- not what was intended. The best > way to > do this is C< my @randoms = map {int rand 100} 0..100; >, which is > rather yucky -- conceptually, you aren't trying to transform one > list > into another. OTOH, C< my @randoms; push @randoms, int rand 100 > for > 0..100 > is even yuckier. > > Perhaps if the LHS of a xx operator is a closure, it should run > the > closure each time around... or perhaps there should be an xxx > operator. > (Both suggestions from BrowserUk's reply, > http://perlmonks.org/index.pl?node_id=375344). The former raises > the > question of what you do if you really want to repeat a coderef, > and the > later raises the possibly of being blocked (really), and starts to > become confusing -- the difference between x and xx is sensical -- > the > former repeats one thing, the later many... but what's the > reasoning for > xxx, other then that it's like xx? How will users be able to > remember > which is which?= When I think about your description of xxx, I summarized it in my head as "Call a coderef a certain number of times, and then collect the results." That's pretty much what map is, except that xxx is infix and map is prefix. @results = { ... } xxx 100; @results = map { ... } 1.. 100; Doesn't seem that special to me. - Joe