blob: ab796a6ce45e00767f60585f2dd78ba188129689 [file] [log] [blame] [view]
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +01001[TOC](Readme.md) [Prev](numbers.md) [Next](rangedef.md)
2
Marcel van Lohuizen3e592b42019-01-11 20:31:29 +01003_Types ~~and~~ are Values_
Marcel van Lohuizenaf0932f2019-01-11 13:03:56 +01004
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +01005# Ranges
6
7Ranges define an inclusive range of valid values.
8They work on numbers, strings, and bytes.
9
10The type of a range is the unification of the types of the start and end
11value.
12
13Unifying two ranges results in the overlapping range or an error if there
14is no overlap.
15
16<!-- CUE editor -->
17```
18rn: 3..5 // type int | float
19ri: 3..5 & int // type int
20rf: 3..5.0 // type float
21rs: "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```
36a: 3.5
37b: _|_
Jonathan Amsterdame4790382019-01-20 10:29:29 -050038c: 3 <!-- jba: this should be 3.0, right? -->
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +010039d: "ma"
40e: _|_
41r1: 3..7
Jonathan Amsterdame4790382019-01-20 10:29:29 -050042```