On Tue, Aug 25, 2009 at 02:58:05PM -0700, Jon Lang wrote:
: Michael Zedeler wrote:
: >> The obvious (default) choice for a step size would be the precision of
: >> the more precise of the two values.  So 0.0001 in your example above.
: >>
: >
: > Well... maybe. How do you specify the intended precision, then? If I want
: > the values from 1 to 2 with step size 0.01, I guess that writing
: >
: > 1.00 .. 2.00
: >
: > won't be sufficient. Trying to work out the step size by looking at the
: > precision of things that are double or floats doesn't really sound so
: > feasible, since there are a lot of holes in the actual representation, so
: > 1.0001 may become 1.0, yielding very different results.
: >
: > It could be really nice to come up with something dwimmy, but I can't really
: > se any really good candidates, when it comes to floating point numbers and
: > strings.
: 
: For floating point numbers, assume a default step size of 1, just like
: integers; use the :by adverb to specify a different step size, either
: by supplying a floating point number to be added in or by supplying a
: block that generates the next step when fed the current one.  So:
: 
: 1.00 .. 2.00 # 1.00, 2.00
: 1.00 .. 2.00 :by .01 # 1.00, 1.01, 1.02, ..., 1.98, 1.99, 2.00

Note that your :by adverb is malformed; it must be :by(.01), or it's
parsed as a boolean :by followed by a term.

Another note, it's likely that numeric literals such as 1.23 will turn
into Rats rather than Nums, at least up to some precision that is
pragmatically determined.

: Also, I want to second David Green's point: we're not talking "Range"
: and "Interval" here; we're talking "Range" and "Series".  A Series
: would be a kind of Range that has the additional ability of generating
: a list.  The :by adverb would be a property of a Series, but not a
: Range.  Using Num for your endpoints would result in a Series; using
: Complex for your endpoints should result in an error: Complex numbers
: don't have a viable definition of "before" or "after", let alone
: "between".

We already make this distinction in the spec.  A Range means an
"interval", possibly annotated with a step, but this is meaningless
unless the range is iterated.   An attempt to use such a Range in a
list produces a RangeIterator, which yields a series of values.

However, the name "series operator" is already reserved to mean
infix:<...> rather than infix:<..>.  So your second example above
basically turns into this series:

    1.00 ... { $_ + 0.01 if $_ < 2.00 };

except that 1.00 .. 0.00 produces (), not 1.00.  A more exact
translation might be

    () ... -> $x = (1.00-0.01) { $x + 0.01 if $x < 2.00 };

I am currently assuming such loops will default to Rat rather than
Num for numbers that aren't too far off the beaten path, where
"on the beaten track" is defined as rats that fit into a pair of
int64s or so, that is, which can be represented with rat64.

Larry

Reply via email to