Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 1 | [TOC](Readme.md) [Prev](scopes.md) [Next](aliases.md) |
| 2 | |
Marcel van Lohuizen | af0932f | 2019-01-11 13:03:56 +0100 | [diff] [blame] | 3 | _References and Visibility_ |
| 4 | |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 5 | # Accessing Fields |
| 6 | |
| 7 | Selectors access fields within a struct using the `.` notation. |
| 8 | This only works if a field name is a valid identifier and it is not computed. |
| 9 | For other cases one can use the indexing notation. |
| 10 | |
| 11 | |
| 12 | <!-- CUE editor --> |
| 13 | ``` |
| 14 | a: { |
| 15 | b: 2 |
| 16 | "c-e": 5 |
| 17 | } |
| 18 | v: a.b |
| 19 | w: a["c-e"] |
| 20 | ``` |
| 21 | |
| 22 | <!-- result --> |
| 23 | ``` |
| 24 | a: { |
| 25 | b: 2 |
| 26 | } |
| 27 | v: 2 |
| 28 | w: 5 |
| 29 | ``` |