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