On Wed, Feb 25, 2009 at 02:34:50PM -0800, Jon Lang wrote:
: Mark J. Reed wrote:
: > I do quite like the magical postfix %, but I wonder how far it should
: > go beyond ±:
: >
: > $x += 5%; # becomes $x += ($x * .05)? Or maybe $x *= 1.05 ?
: > $x * 5%; # becomes $x * .05 ?
:
: If it works with ±, it ought to work with + and -. Rule of thumb: if
: there's no easy way to answer "5% of what?" then default to "5% of
: 1.0", or 0.05. +, -, and ± would need to be set up to provide the
: necessary answer for "of what?" by means of setting Whatever; and by
: basing it on Whatever, you have other options, such as:
:
: @a[50%] # accesses the middle item in the list, since Whatever is
: set to the length of the list.
Coolness.
: Concerning "-> $val, $err { [..^] $val - $err, $val + $err }" vs "->
: $val, $err { any $val - $err, $val + $err }": I'm not sold on the
: notion that Huffman coding might imply that ± should go with the
: former. Perhaps an argument can be made for it; but I suspect that
: the relative commonness of the two uses is extremely similar (which,
: per Huffman coding, would imply that their names should have similar
: lengths). Whichever one we go with, we have a conundrum: if we use ±
: as the name of the latter, the conundrum is that the only other
: intuitive name for the former that has thus far been proposed (i.e.,
: "within") is too long; if we use ± as the name for the former, the
: conundrum is that no other intuitive name has been proposed for the
: latter.
:
: So: what we need are proposals for short, understandable names for
: each operator. Suggestions?
I'm not sure we should give up on unification so soon. Hmm.
Here's another approach. Suppose we define
$a ± $b
to mean something
$a ..^ $b :interval
and :interval causes the Range object to return $a and $b in list
context. Then, since any() supplies list context, we could write
if $x == any($a ± $b) {...}
That seems a bit ugly though. Another way would be to define ± as
simple half-open Range and then overload comparison:
multi sub infix:<==>(Num $x,Range $r) {
$x == any($r.minmax);
}
Of course, that would potentially introduce a failure mode where
people say == when they mean ~~, or vice versa. Maybe that wouldn't
be a big problem in practice.
Larry