# Modules and imports

A file is a module. `export` decides what leaves it, and an import names what it takes.

## Importing

`import { a, b } from "std/strings"` takes two names. `import * as math from "std/math"` takes the module under one name and reaches its exports as `math.min`.

A top-level name is program-wide, so two linked modules cannot both export `parse`. The namespace form is the answer, and the compiler suggests it by name when the collision happens.

A remote import names `github:`, `gist:` or `https:`. It is pinned in `vyrn.lock` and cached under `~/.vyrn`. `--offline` refuses to fetch, and [Projects and dependencies](https://vyrn-lang.github.io/tooling/projects.html) covers the rest.

```vyrn
// An import names what it takes. A namespace import takes the whole module
// under one name, which is how two modules that export the same name coexist.
import { joinWith, padStart } from "std/strings"
import * as math from "std/math"

export fn demo() -> String {
    let padded = padStart("7", 4, "0")
    let clamped = math.clamp(42, 0, 10)

    return joinWith(["padded  \{padded}", "clamped \{clamped}", "min     \{math.min(3, 9)}"], "\n")
}

fn main() -> Int64 {
    print(demo())
    return 0
}
```

Built output:

```
padded  0007
clamped 10
min     3
```

---

From https://vyrn-lang.github.io/guide/modules.html — generated by `site/export.vyrn` from the Vyrn repository.
