~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to doc/manual/modules.rst

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-02-06 17:54:29 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130206175429-13br5kqpkfjqdmre
Tags: 0.0.0+20130206.git32ff5759-1
* New upstream snapshot.
* debian/copyright: reflect upstream changes
* debian/rules: update get-orig-source to reflect upstream changes
   + Don't ship nginx
   + Adapt for new configure-random target in deps/Makefile
* Enable build of Tk wrapper.
   + debian/control: add build dependency on tk-dev
   + debian/rules: add tk rule to build-arch
* debian/julia.install: install VERSION and COMMIT files
* no-webrepl.patch: new patch
* Refresh other patches
* Add source override for config.status file under deps/random/

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
can control which names from other modules are visible (via importing),
12
12
and specify which of your names are intended to be public (via exporting).
13
13
 
14
 
The following example illustrates the major features of modules::
 
14
The following example demonstrates the major features of modules. It is 
 
15
not meant to be run, but is shown for illustrative purposes::
15
16
 
16
17
    module MyModule
17
18
    using Lib
29
30
    show(io, a::MyType) = print(io, "MyType $(a.x)")
30
31
    end
31
32
 
32
 
Note that the style is not
33
 
to indent the body of the module, since that would typically lead to
34
 
whole files being indented.
35
 
 
36
 
This module defines a type ``MyType``, and two functions. Function ``foo``
37
 
and type ``MyType`` are
38
 
exported, and so will be available for importing into other modules.
39
 
Function ``bar`` is private to ``MyModule``.
40
 
 
41
 
The statement ``using Lib`` means that a module called ``Lib``
42
 
will be available for resolving names
43
 
as needed. When a global variable is encountered that has no definition in
44
 
the current module, the system will search for it in ``Lib`` and import it
45
 
if it is found there.
 
33
Note that the style is not to indent the body of the module, since
 
34
that would typically lead to whole files being indented.
 
35
 
 
36
This module defines a type ``MyType``, and two functions. Function
 
37
``foo`` and type ``MyType`` are exported, and so will be available for
 
38
importing into other modules.  Function ``bar`` is private to
 
39
``MyModule``.
 
40
 
 
41
The statement ``using Lib`` means that a module called ``Lib`` will be
 
42
available for resolving names as needed. When a global variable is
 
43
encountered that has no definition in the current module, the system
 
44
will search for it in ``Lib`` and import it if it is found there.
46
45
This means that all uses of that global within the current module will
47
46
resolve to the definition of that variable in ``Lib``.
48
47
 
93
92
There are three important standard modules: Main, Core, and Base.
94
93
 
95
94
Main is the top-level module, and Julia starts with Main set as the
96
 
current module.
97
 
Variables defined at the prompt go in Main, and ``whos()`` lists variables
98
 
in Main.
 
95
current module.  Variables defined at the prompt go in Main, and
 
96
``whos()`` lists variables in Main.
99
97
 
100
98
Core contains all identifiers considered "built in" to the language, i.e.
101
99
part of the core language and not libraries. Every module implicitly
115
113
 
116
114
If these definitions are not wanted, modules can be defined using the
117
115
keyword ``baremodule`` instead. In terms of ``baremodule``, a standard
118
 
``module`` looks like this:
 
116
``module`` looks like this::
119
117
 
120
118
    baremodule Mod
121
119
    using Base
132
130
it is not exported. This is often useful when debugging.
133
131
 
134
132
Macros must be exported if they are intended to be used outside their
135
 
defining module.
136
 
Macro names are written with ``@`` in import and export statements, e.g.
137
 
``import Mod.@mac``.
 
133
defining module.  Macro names are written with ``@`` in import and
 
134
export statements, e.g.  ``import Mod.@mac``.
138
135
 
139
136
The syntax ``M.x = y`` does not work to assign a global in another module;
140
137
global assignment is always module-local.