Define a primitive data type: Difference between revisions

m
Fixed lang tags.
(→‎{{header|Perl 6}}: Fixed (Whatever doesn't play nicely with chained comparisons, at least at the moment).)
m (Fixed lang tags.)
Line 3:
 
=={{header|Ada}}==
<lang ada>type My_Type is range 1..10;</lang>
The compiler identifies the range of valid values from the range specification ''1..10'' and automatically builds in bounds checking where it is needed. The compiler is smart enough to omit bounds checking when it is not needed.
<lang ada>A : My_Type := 3;
B : My_Type := A;</lang>
The compiler will omit bounds checking for the assignment of A to B above because both values are of My_Type. A cannot hold a value outside the range of 1..10, therefore the assignment cannot produce an out of bounds result.
 
Line 16:
 
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
<!-- Note: I cannot use <lang=algol algol68> here because algol support UTF-8 characters ÷×≤≥↑ etc, and some code is COMMENTED out, sorry -->
# assume max int <= ABS - max negative int #
INT max bounded = ( LENG max int * max int > long max int | ENTIER sqrt(max int) | max int );
Line 656:
{{works with|Rakudo|#22 "Thousand Oaks"}}
 
<lang perlperl6>subset OneToTen of Int where { 1 <= $^n <= 10 }
 
my OneToTen $n = 5;
Line 663:
<code>{ 1 <= $^n <= 10 }(11)</code> returns a false value, so the second assignment throws an exception. You can use any unary function in place of <code>{ 1 <= $^n <= 10 }</code>, so this, for example, is also legal:
 
<lang perlperl6>subset Prime of Int where { $^n > 1 and $^n !% none 2 .. sqrt $^n }</lang>
 
=={{header|Python}}==
Line 688:
>>> type(x)
<class '__main__.num'>
>>> </lang>
 
=={{header|Ruby}}==
Anonymous user