On Fri, Jul 16, 2010 at 3:49 PM, Carl Mäsak <cma...@gmail.com> wrote:
> Aaron (>): > > [...] > > > > Many useful results from this suggested change: > > > > "C" .. "A" = <C B A> (Rakudo: <>) > > Regardless of the other traits of your proposed semantics, I think > permitting reversed ranges such as the one above would be a mistake. > Why are you calling that a "reversed range"? It's not reversed, it's a range like any other. The ordering of the terminator elements is only interesting if you start pulling elements out. As a range, ordering isn't really significant. > Rakudo gives the empty list for ranges whose lhs exceeds (fsvo > "exceeds") its rhs, because that's the way ranges work in Perl. The > reason ranges work that way in Perl (in my understanding) is that it's > the less surprising behavior when the endpoints are determined at > runtime. > In Perl 5, if that's what you mean, "C" .. "A" produces the letters from C to Z. I have no rational explanation for why, but I suggest we avoid emulating this behavior in Perl 6. > For explicitly specifying a reverse list of characters, there's still > `reverse "A" .. "C"`, which is not only a straightforward idiom and > huffmanized about right, but also good documentation for the reader. > reverse("A" .. "C") is not the same as "C" .. "A". Observe: $ ./perl6 -e 'say reverse("A" .. "C").perl' ["C", "B", "A"] $ ./perl6 -e 'say ("A" .. "C").perl' "A".."C" In order for reverse to work lazily, it would have to add a wrapper to the iterator that asked for its last element first, and it's not clear to me that one CAN ask for an iterators last element without unrolling it. For single characters, that's not TOO bad, but for strings.elems > 1 you could blow out your RAM on even fairly trivial strings. -- Aaron Sherman Email or GTalk: a...@ajs.com http://www.ajs.com/~ajs