On Mon, Feb 23, 2009 at 11:54:44PM -0600, Chris Dolan wrote:
> On Feb 23, 2009, at 11:16 PM, Larry Wall wrote:
>>     if $x ~~ $y ± $epsilon {...}
>> where infix:<±> turns the single value into a range for the  
>> smartmatch.
> That's very cool.  However, my first impression is that "$y ± $epsilon" 
> maps more naturally to "any($y-$epsilon, $y+$epsilon)" than to a range.

I'm using ±  more in the engineering sense than the mathematical sense.
Maybe there's some way to finesse it to mean both, though I suspect
any such scheme would make it difficult to catch brainos.  If there's
a subtle distinction between

    if $x ~~ $y ± $epsilon {...}


    if $x == $y ± $epsilon {...}

then it will be sure to trip people up.

It would be possible to make it a method:

    if $x ~~ $y.within($epsilon)

but that does late binding, too late to give info to the optimizer.
The adverbial solution might or might not have the same problem.
In any case, adverbs on operators tend to be a design smell.

So it might be better as a (very tight?) operator, regardless of
the spelling:

    $x ~~ $y within $epsilon

For what it's worth, ± does happen to be in Latin-1, and therefore
officially fair game for Standard Perl.  By the way, the mathematical
definition can be derived from the engineering definition with

    if $x == ($x ± $epsilon).minmax.any

The problem with defining it the other direction is that junctions
tend to lose ordering information of their eigenstates, and we can't
just flip mins and maxes when we feel like it, or degenerate null
ranges get broken.


Reply via email to