blob: dd1889f6e04665f4d3f20d4eaecf4e5fd48cd387 [file] [log] [blame] [view]
Marcel van Lohuizen3e592b42019-01-11 20:31:29 +01001[TOC](Readme.md) [Prev](rangedef.md) [Next](templates.md)
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +01002
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# Lists
6
7Lists define arbitrary sequences of CUE values.
8A list can be closed or open ended.
Marcel van Lohuizen3eb3a3c2019-01-11 12:39:52 +01009Open-ended lists may have some predefined elements, but may have
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +010010additional, possibly typed elements.
11
12In the example we define `IP` to be a list of `4` elements of type `uint8`, which
Marcel van Lohuizen62b87272019-02-01 10:07:49 +010013is a predeclared value of `>=0 & <=255`.
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +010014`PrivateIP` defines the IP ranges defined for private use.
15Note that as it is already defined to be an `IP`, the length of the list
Marcel van Lohuizen3eb3a3c2019-01-11 12:39:52 +010016is already fixed at `4` and we do not have to specify a value for all elements.
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +010017Also note that instead of writing `...uint8`, we could have written `...`
18as the type constraint is already already implied by `IP`.
19
Marcel van Lohuizen3eb3a3c2019-01-11 12:39:52 +010020The output contains a valid private IP address (`myIP`)
21and an invalid one (`yourIP`).
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +010022
23<!-- CUE editor -->
24```
25IP: 4 * [ uint8 ]
26
27PrivateIP: IP
Marcel van Lohuizen62b87272019-02-01 10:07:49 +010028PrivateIP: [10, ...uint8] | [192, 168, ...] | [172, >=16 & <=32, ...]
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +010029
30myIP: PrivateIP
31myIP: [10, 2, 3, 4]
32
33yourIP: PrivateIP
34yourIP: [11, 1, 2, 3]
35```
36
37<!-- result -->
38```
Marcel van Lohuizen62b87272019-02-01 10:07:49 +010039IP: [>=0 & <=255, >=0 & <=255, >=0 & <=255, >=0 & <=255]
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +010040PrivateIP:
Marcel van Lohuizen62b87272019-02-01 10:07:49 +010041 [10, >=0 & <=255, >=0 & <=255, >=0 & <=255] |
42 [192, 168, >=0 & <=255, >=0 & <=255] |
43 [172, >=16 & <=32, >=0 & <=255, >=0 & <=255]
Marcel van Lohuizen75cb0032019-01-11 12:10:48 +010044
45myIP: [10, 2, 3, 4]
46yourIP: _|_
47```