Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 1 | [TOC](Readme.md) [Prev](packages.md) [Next](operators.md) |
| 2 | |
Marcel van Lohuizen | af0932f | 2019-01-11 13:03:56 +0100 | [diff] [blame] | 3 | _Modules, Packages, and Instances_ |
| 4 | |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 5 | # Imports |
| 6 | |
| 7 | A CUE file may import definitions from builtin or user-defined packages. |
Marcel van Lohuizen | 3eb3a3c | 2019-01-11 12:39:52 +0100 | [diff] [blame] | 8 | A CUE file does not need to be part of a package to use imports. |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 9 | |
| 10 | The example here shows the use of builtin packages. |
| 11 | |
| 12 | This code groups the imports into a parenthesized, "factored" import statement. |
| 13 | |
| 14 | You can also write multiple import statements, like: |
| 15 | |
| 16 | ``` |
| 17 | import "encoding/json" |
| 18 | import "math" |
| 19 | ``` |
| 20 | |
| 21 | But it is good style to use the factored import statement. |
| 22 | |
| 23 | <!-- CUE editor --> |
| 24 | ``` |
| 25 | import ( |
| 26 | "encoding/json" |
| 27 | "math" |
| 28 | ) |
| 29 | |
| 30 | data: json.Marshal({ a: math.Sqrt(7) }) |
| 31 | ``` |
| 32 | |
| 33 | <!-- result --> |
| 34 | ``` |
| 35 | data: "{\"a\":2.6457513110645907}" |
| 36 | ``` |