2 ms·
In this example, how do you get an instance of `Age`? i.e. If a user is asked for their age and they type in a number
by tubthumper8 3y ago
In this example, how do you get an instance of `Age`? i.e. If a user is asked for their age and they type in a number
- Jtsummers 3y agoAda has had generics since the start. https://learn.adacore.com/courses/intro-to-ada/chapters/generics.html https://learn.adacore.com/courses/intro-to-ada/chapters/gene... - Generics in Ada. This is from a good intro course for Ada and the site has several other courses as well. https://learn.adacore.com/courses/intro-to-ada/chapters/generics.html#example-i-o-instances https://learn.adacore.com/courses/intro-to-ada/chapters/gene... - generic IO portion of the above. A sketch, you'd need to place these lines in valid locations since it won't run directly like this but these are the lines you'd use: type Age is range 0..150; package Age_IO is new Ada.Text_IO.Integer_IO (Age); -- declared somewhere A : Age; -- from user input Age_IO.Get(A); -- if we "use" the above use Age_IO; -- now we can skip the prefix Get(A); This would result in a runtime error if the read value is out of range.