Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 1 | [TOC](Readme.md) [Prev](selectors.md) [Next](emit.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 | # Aliases |
| 6 | |
| 7 | An alias defines a local macro. |
| 8 | |
| 9 | A typical use case is to provide access to a shadowed field. |
| 10 | |
Jonathan Amsterdam | abeffa4 | 2019-01-20 10:29:29 -0500 | [diff] [blame] | 11 | Alias are not members of a struct. They can be referred to only within the |
| 12 | struct, and they do not appear in the output. |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 13 | |
| 14 | <!-- CUE editor --> |
| 15 | ``` |
Jonathan Amsterdam | e479038 | 2019-01-20 10:29:29 -0500 | [diff] [blame] | 16 | A = a // A is an alias for a |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 17 | a: { |
| 18 | d: 3 |
| 19 | } |
| 20 | b: { |
| 21 | a: { |
| 22 | // A provides access to the outer "a" which would |
| 23 | // otherwise be hidden by the inner one. |
| 24 | c: A.d |
| 25 | } |
| 26 | } |
| 27 | ``` |
| 28 | |
| 29 | <!-- result --> |
| 30 | ``` |
| 31 | a: { |
| 32 | d: 3 |
| 33 | } |
| 34 | b: { |
| 35 | a: { |
| 36 | c: 3 |
| 37 | } |
| 38 | } |
| 39 | ``` |