Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 1 | [TOC](Readme.md) [Prev](numbers.md) [Next](rangedef.md) |
| 2 | |
Marcel van Lohuizen | 3e592b4 | 2019-01-11 20:31:29 +0100 | [diff] [blame] | 3 | _Types ~~and~~ are Values_ |
Marcel van Lohuizen | af0932f | 2019-01-11 13:03:56 +0100 | [diff] [blame] | 4 | |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 5 | # Ranges |
| 6 | |
| 7 | Ranges define an inclusive range of valid values. |
| 8 | They work on numbers, strings, and bytes. |
| 9 | |
| 10 | The type of a range is the unification of the types of the start and end |
| 11 | value. |
| 12 | |
| 13 | Unifying two ranges results in the overlapping range or an error if there |
| 14 | is no overlap. |
| 15 | |
| 16 | <!-- CUE editor --> |
| 17 | ``` |
| 18 | rn: 3..5 // type int | float |
| 19 | ri: 3..5 & int // type int |
| 20 | rf: 3..5.0 // type float |
| 21 | rs: "a".."mo" |
| 22 | |
| 23 | { |
| 24 | a: rn & 3.5 |
| 25 | b: ri & 3.5 |
| 26 | c: rf & 3 |
| 27 | d: "ma" |
| 28 | e: "mu" |
| 29 | |
| 30 | r1: 0..7 & 3..10 |
| 31 | } |
| 32 | ``` |
| 33 | |
| 34 | <!-- result --> |
| 35 | ``` |
| 36 | a: 3.5 |
| 37 | b: _|_ |
Jonathan Amsterdam | e479038 | 2019-01-20 10:29:29 -0500 | [diff] [blame] | 38 | c: 3 <!-- jba: this should be 3.0, right? --> |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 39 | d: "ma" |
| 40 | e: _|_ |
| 41 | r1: 3..7 |
Jonathan Amsterdam | e479038 | 2019-01-20 10:29:29 -0500 | [diff] [blame] | 42 | ``` |