|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
Subrange typesSee this in the manual: https://nim-lang.org/docs/manual.html#types-subrange-types "A subrange type is a range of values from an ordinal or floating-point type (the base type). To define a subrange type, one must specify its limiting values -- the lowest and highest value of the type." Examples: type Natural = range[0 .. high(int)] # as defined in `system` Positive = range[1..high(int)] # as defined in `system` Negative = range[low(int) .. -1] # I missed it from `system` # PositiveFloat = range[0.0..Inf] var a: Natural b: Positive c: int a = 5 # OK #a = -2 # Error b = 3 # OK #b = -10 # Error c = a # OK c = b # OK var f: PositiveFloat f = 3.14 # OK #f = -2.5 # Error Range object (1..6) and range types (range[1..6])In Nim, "range" can mean two different things, and they shouldn't be confused. type DiceRoll = range[1..6] # ^ ^ # A B
|
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |