Namespaces in the Alexa Conversations Description Language


In Alexa Conversations Description Language (ACDL) files, you organize name declarations into namespaces. Each ACDL file corresponds to a module that consists of a single namespace declaration.

You can refer to names from other namespaces by using fully qualified names. Alternatively, you can use an import declaration so that you can reference a name without its namespace qualifier.

Declare namespaces

To declare a namespace, you use the namespace keyword followed by a namespace name and a new line.

namespaceDeclaration
   : 'namespace' qualifiedName NEWLINE
   ;

qualifiedName
   : IDENTIFIER (DOT IDENTIFIER)*
   ;

Use namespaces

The fully qualified names of all the names declared within a namespace include the namespace as a prefix. For example, in the following ACDL file, the fully qualified name of myAction is org.example.mydialog.myAction.

// file: mydialog.acdl

namespace org.example.mydialog

action Nothing myAction()

Multiple ACDL files can have the same namespace. You don't need to use the namespace qualifier to refer to names declared in different ACDL files with the same namespace.

In the following example, both files (mydialog1.acdl and mydialog2.acdl) have the same namespace.

// file: mydialog1.acdl

namespace org.example.mydialog

nameA = "hello ACDL"

// file: mydialog2.acdl

namespace org.example.mydialog

nameB = nameA // nameA is declared in mydialog1.acdl and referenced without the namespace qualifier.

Import namespaces

To reference a name without its namespace qualifier, you use an import declaration.

Without using an import declaration, the only way to refer to a name declared in another namespace is by using its fully qualified name.

There are two types of import declarations:

Single import declaration

You can import a single name by giving its fully qualified name. This way, you don't need to use the namespace qualifier within the ACDL file in which the import declaration appears.

The imported name must be the fully qualified name of an action declaration, a type declaration, a named expression, or dialog declarations. If the imported name doesn't exist, there's a compilation error.

If you import different declarations of the same name without their namespace qualifiers into the same ACDL file, you must reference the names with their fully qualified names.

The following example shows a single import declaration.

namespace org.example.mydialog

import com.amazon.alexa.schema.Restaurant

The following example shows a duplicate import declaration. Expression nameB = nameA causes a compilation error because the compiler can't uniquely resolve nameA.

// This example causes a compiler error.

// file: mydialog1.acdl
namespace org.example.mydialog1

nameA = "hello ACDL1"

// file: mydialog2.acdl
namespace org.example.mydialog2

nameA = "hello ACDL2"

// file: mydialog.acdl
namespace org.example.mydialog

import org.example.mydialog1.nameA
import org.example.mydialog2.nameA

nameB = nameA

Wildcard import declaration

You can import an entire namespace by using a wildcard import declaration. This way, you can reference all names declared in the namespace without the namespace qualifier in the ACDL file in which the import declaration appears.

The following example shows a wildcard import declaration.

namespace org.example.mydialog

import com.amazon.alexa.schema.*

type Person {
  String firstName
  String lastName
  Number age
}

In the previous example, com.amazon.alexa.schema must be a valid namespace; otherwise, it causes a compilation error. The String and Number types are declared in the com.amazon.alexa.schema namespace, so you can refer to them without namespace qualifiers.

Apparent hierarchies of namespaces

Namespaces aren't related to each other, even if the namespace names appear to be hierarchal.

In the following example, importing com.amazon.alexa.* imports all the names declared in the com.amazon.alexa namespace, but it doesn't import names declared in the com.amazon.alexa.schema namespace. You must use separate import declarations to import names from both namespaces.

namespace org.example.mydialog

import com.amazon.alexa.*
import com.amazon.alexa.schema.*

Was this page helpful?

Last updated: Nov 27, 2023