Case Range Statement ..

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Fri Jul 10 11:40:02 PDT 2009


Walter Bright wrote:

> Having a step size requires, of course, a third operand. This doesn't
> work too well with infix operator notation (the only 3 operand infix
> operator is ?:).
> 
> Having such a third operand, however, should mesh quite well with
> Andrei's range library construct.

In the programming language I'm currently designing, .. is overloaded twice
to get the desired effect.

----------------------------------------
Interval interval(int a, int b) {
    result.lower <- a;
    result.upper <- b;
}

Interval interval(Interval a, int b) {
    result <- a;
    result.stride <- b;
}

for (i, 1..10..-1) {
    // i = 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
}
----------------------------------------

(Clarification: 'interval' is the function name used to overload the ..
operator. <- is the assignment operator. 'result' is automatically declared
and returned.)

You see, .. can remain a binary operator. Perhaps something like this can
work for D.

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list