Added your useful answer to the FAQ in PR 7553 <https://github.com/JuliaLang/julia/pull/7553>
--Peter On Wednesday, July 9, 2014 8:13:55 AM UTC-7, Steven G. Johnson wrote: > > No, you are not allowed to have a "using" statement inside a function. > > If you want to import a module but only use its symbols inside a specific > function or set of functions, you have two options: > > 1) Use import: > > import Foo > function bar(...) > ... refer to Foo symbols via Foo.baz ... > end > > > This loads the module Foo and defines a variable "Foo" that refers to > the module, but does not import any of the other symbols from the module > into the current namespace. You refer to the Foo symbols by their > qualified names Foo.bar etcetera. > > 2) Wrap your function in a module > > module Bar > > export bar > > using Foo > > function bar(...) > > ... refer to Foo.baz as simply baz .... > > end > > end > > using Bar > > > This imports all the symbols from Foo, but only inside the module Bar. >
