develooper Front page | perl.perl6.language | Postings from July 2010

Re: Suggested magic for "a" .. "b"

Thread Previous | Thread Next
From:
Darren Duncan
Date:
July 20, 2010 22:56
Subject:
Re: Suggested magic for "a" .. "b"
Message ID:
4C468C1A.4020506@darrenduncan.net
Aaron Sherman wrote:
> 2) The spec doesn't put this information anywhere near the definition of the
> range operator. Perhaps we can make a note? This was a source of confusion
> for me.

My impression is that a "Range" primarily defines an "interval" in terms of 2 
endpoint values such that it defines a possibly infinite set values between 
those endpoints.

For example, 'aa'..'bb' is an infinite sized set that includes every possible 
character string that starts with the letter 'a', plus every one that starts 
with the string 'ba'.  And so, asking $anysuchstring ~~ 'aa'..'bb' is TRUE.

(Note that for ".." to work, its 2 arguments would need to be of the same type, 
so that we know which set of rules to follow.  Or to be specific, the generic 
"eqv" operator, or "before" etc would have to be defined that takes both of the 
".." arguments as its arguments.  Although this might be fuzzed a bit if the 
spec defines somewhere about automatic casting.  For example, if someone said 
'foo'..42 then I would expect that to fail.)

A "Range" can also be used in a limited fashion to generate a finite list of 
values, but that is not its primary purpose, and the "..." operator does that 
job much better.

> 3) It seems that there are two competing multi-character approaches and both
> seem somewhat valid. Should we use a pragma to toggle behavior between A and
> B:
> 
>  A: "aa" .. "bb" contains "az"
>  B: "aa" .. "bb" contains ONLY "aa", "ab", "ba" and "bb"

I would find A to be the only reasonable answer.

If you want B's semantics then use "..." instead; ".." should not be overloaded 
for that.

If there were to be any similar pragma, then it should control matters like 
"collation", or what nationality/etc-specific subtype of Str the 'aa' and 'bb' 
are blessed into on definition, so that their collation/sorting/etc rules can be 
applied when figuring out if a particular $foo~~$bar..$baz is TRUE or not.

-- Darren Duncan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About