Define a primitive data type: Difference between revisions

Content added Content deleted
(Added Java example)
m (Switch to header template)
Line 2:
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
 
==[[{{header|Ada]]}}==
[[Category:Ada]]
 
type My_Type is range 1..10;
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.
Line 79 ⟶ 77:
};
 
==[[{{header|E]]}}==
[[Category:E]]
 
def MyNumber := 1..10
 
Line 239 ⟶ 235:
Similarly, we could declare the subtype of floating point numbers with restricted exponent, and so on.
 
==[[{{header|Perl]]}}==
[[Category:Perl]]
'''Interpreter:''' [[Perl]] 5
 
Line 264 ⟶ 259:
# dies, too small. string is 0 interpreted numerically
 
==[[{{header|Toka]]}}==
[[Category:Toka]]
 
needs quotes
{