Re: Numeric Types
[email protected] (Dave Whipp) Fri, 15 Nov 2002 01:10:17 -0800
| Newsgroups | perl.perl6.documentation |
|---|---|
| Message-ID | <[email protected]> |
Michael Lazzaro wrote:
>
> Does someone from internals want to take on the task of finalizing this
> list? We need to decide if we want to support none, some, or all of
> these types/aliases.
>
> -----
>
> The Full List of Numeric Types
>
> In addition to the standard int and num, there are a great number of
> other numeric types available. If your program makes use of code written
> in other languages, such as C, C++, Java, C#, etc., or if you want your
> program to make use of low-level system or library calls, you will
> frequently need to use more exact types that correspond to what the
> other language expects to see. You might also wish to use the more
> specific primitive types when you can guarantee certain bounds
> restrictions on numbers, and simply want to squeeze every unnecessary
> byte out of the generated code.
>
> [ very long list snipped]
I still don't understand why we want to go to all this hassle of
completing a vast list primitives to support mappings onto languages and
architectures that have yet to be invented. I still prefer to keep
things simple:
my Number $a is ctype("unsigned long int") = 42;
my Number $b is ctype("my_int32") = 42;
The definition of this type depends on the system you're running on. If
you require a specific range, independent on compiler/architecture: then
primitive types is the wrong mechanism:
my Integer $a is range(0..16:ffffffff) = 42;
my Real $b is range(0..^1;0.001) = rand; # correct syntax?
my String $x is null_terminated is ctype(const char *) = "hello";
You can rename the types if you want; but properties are a better
representation of constraints than type names: more precise, and more
flexible.
Dave.