When building programs, it can be very useful to make use of reusable code libraries written by others. Such libraries are distributed as packages.

import

To make use of a package in your program, employ the import command in the global area:

import math3d
import opengl

This example imports two packages. Cone's build tool (Congo) will automatically find, download, and prepare these packages for inclusion in your program. Thereafter, you can make use of the types, functions, templates, macros that are defined by these packages as if they were now a part of your program.

A package name may be enclosed in double quotes, if desired. This option is useful when a package's name includes symbols not allowed in a variable name. It may also be used whenever one wants to refer to a package using the folder or URL path where the package may be found.

Note: It is never necessary to import the standard library (std). It is automatically included as part of every program.

Namespace Path

To reference entities defined by the package, a namespace path may be used (since an imported package is treated as a module namespace). So we can reference the Point3 type in the math3d package, by qualifying (with a double colon) the type's name with the package's namespace:

fn move(pos &math3d::Point3, delta math3d::Point3)
		pos += delta

Typically, path names are relative to the current module. This behavior can be overridden by using one of two special prefixes:

Namespace folding

The default practice of wrapping the named items of an external packages in its own namespace is hygienic. It prevents polluting the program's namespace with unanticipated names that might collide.

However, frequent use of fully-qualified path names for external package entities can get tedious to type and read. The import command provides several ways to fold the package's namespace into the current namespace, thereby avoiding the need to qualify a name with a path prefix.

To fold in specific names from the package's namespace:

import math3d Point3, Mat3

fn move(pos &Point3, delta Point3)
		pos += delta

To fold in an alias for specific names:

import math3d Point3 as Point

fn move(pos &Point, delta Point)
		pos += delta

Or one can fold in all names from the package using '*':

import math3d *

fn move(pos &Point3, delta Point3)
		pos += delta

_