Is it not possible to emulate this already with classes? I think you can
use the implicitly-called construct method, e.g.

class myint {
    private var i: int;
    function myint(x: int) {
       this.i = int;
    }
    meta static function invoke(x: int) {
       if (x > SOME_MAX_VALUE || x < SOME_MIN_VALUE)
          throw some_error;
       return new myint(x);
    }
}

Or something like that. Above code is probably wrong. I'm not sure
exactly when and how invoke is called or even what the implicit type
conversion customization protocol is.

However, if it isn't possible to create a class to emulate such
constraints, maybe we ought to do something about it...

-Yuh-Ruey Chen

liorean wrote:
> Hello!
>
> Since we now have a namespace for uint specific math operations, and
> discussion in another thread about using pragmas for throwing if
> assigning to ReadOnly properties... Is it possible we could have a
> look at the idea of adding constrained primitive types or adding a
> pragma changing the mechanism for, or adding a separate set of
> operations, constraining number types by the simple rule of (input >
> output_type.MAX_VALUE) and (input < output_type.MIN_VALUE) throwing an
> out-of-bounds error.
>
> I'm a little concerned that a type of uint allows assigning negatives
> with a silent round-the-corner conversion and allows values of NaN and
> Infinity. (I imagine for example the DOM interfaces that have uint
> constraints really would like these to throw an out-of-bounds
> exception or similar.)
>
> Also, the RI gives an Overflow exception for values 2^32 or greater,
> which I'm not sure whether it's the intended behaviour or a result of
> the underlying implementation that is in fact intended to fail
> silently like the other cases.
>
> >> function fn(input:uint):uint input;
> >> fn(0x7fffffff);
> 2147483647
> >> fn(-0x80000000);
> 2147483648
> >> fn(Infinity);
> 0
> >> fn(NaN);
> 0
> >> fn(0x100000000);
> unhandled exception: Overflow
>
> >> function fn(input:int):int input;
> >> fn(0x7fffffff)
> 2147483647
> >> fn(0x80000000)
> -2147483648
> >> fn(-0x80000000)
> -2147483648
> >> fn(NaN)
> 0
> >> fn(Infinity)
> 0
> >> fn(0x100000000)
> unhandled exception: Overflow
>   
_______________________________________________
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to