Aaron Sherman wrote:
On Wed, Jul 28, 2010 at 11:34 AM, Dave Whipp <d...@dave.whipp.name> wrote:
To squint at this slightly, in the context that we already have 0...1e10 as
a sequence generator, perhaps the semantics of iterating a range should be
unordered -- that is,
for 0..10 -> $x { ... }
is treated as
for (0...10).pick(*) -> $x { ... }
As others have pointed out, this has some problems. You can't implement 0..*
that way, just for starters.
I'd say that' a point in may favor: it demonstrates the integers and
strings have similar problems. If you pick items from an infinite set
then every item you pick will have an infinite number of digits/characters.
In smart-match context, "a".."b" includes "aardvark". It follows that,
unless you're filtering/shaping the sequence of generated items, then
almost every element ("a".."b").Seq starts with an infinite number of "a"s.
Consistent semantics would make "a".."b" very not-useful when used as a
sequence: the user needs to say how they want to avoid the infinities.
Similarly (0..1).Seq should most likely return Real numbers -- and thus
(0..1).pick(*) can be approximated by (0..1).pick(*, :replace), which is
much easier to implement.
So either you define some arbitrary semantics (what those should be is,
I think, the original topic of this thread) or else you punt (error
message). An error message has the advantage that you can always do
something useful, later.
Then the whole question of reversibility is moot.
Really? I don't think it is. In fact, you've simply made the problem pop up
everywhere, and guaranteed that .. must behave totally unlike any other
iterator.
%hash.keys has similarly unordered semantics. Therefore
%hash.keys.reverse is, for most purposes, equivalent to %hash.keys. That
is why I said the question of reversibility becomes moot if you define
the collapse of a range to a sequence to be unordered. It also
demonstrates precedent, so not "totally unlike any other".
Even though it was only a semi-serious proposal, I seem to find myself
defending it. So maybe I was serious, afterall. That argument for DWIM
being ordered pretty much goes away once you tell people to use "..."
for what they intended to mean.
Getting back to 10..0
Yes, I agree with Jon that this should be an empty range. I don't care
what order you pick the elements from an empty range :).