next up previous

10.4.1 Exporting Constructs

The export specification in a defmodule definition is used to indicate which constructs will be accessible to other modules importing from the module being defined. Only deftemplates, defclasses, defglobals, deffunctions, and defgenerics may be exported. A module may export any valid constructs that are visible to it (not just constructs that it defines).

There are three different types of export specifications. First, a module may export all valid constructs that are visible to it. This accomplished by following the export keyword with the ?ALL keyword. Second, a module may export all valid constructs of a particular type that are visible to it. This accomplished by following the export keyword with the name of the construct type followed by the ?ALL keyword. Third, a module may export specific constructs of a particular type that are visible to it. This accomplished by following the export keyword with the name of the construct type followed by the name of one or more visible constructs of the specified type. In the following code, defmodule A exports all of its constructs; defmodule B exports all of its deftemplates; and defmodule C exports the foo, bar, and yak defglobals.

(defmodule A (export ?ALL))
(defmodule B (export deftemplate ?ALL))
(defmodule C (export defglobal foo bar yak))

The ?NONE keyword may be used in place of the ?ALL keyword to indicate either that no constructs are exported from a module or that no constructs of a particular type are exported from a module.

Defmethods and defmessagehandlers cannot be explicitly exported. Exporting a defgeneric automatically exports all associated defmethods. Exporting a defclass automatically exports all associated defmessagehandlers. Deffacts, definstances, and defrules cannot be exported.


next up previous