On Fri, Feb 27, 2015 at 10:46:14PM -0500, Jiahao Chen wrote:
On Fri, Feb 27, 2015 at 5:50 AM, Devendra Ghate <[email protected]>
wrote:
I only imported MyModule.x and was able to overload MyModule.y
(exported function) as well as MyModule.p (not exported) functions.
As far as I understand, there is no difference between an exported
function and non exported function.
Are you sure you cleared the namespace between trying the four versions of
using/import MyModule/.x ?
If you only import MyModule.x, the method definitions for MyModule.p and
MyModule.y are never loaded. You can define a new y function but that is
not the same thing as overloading MyModule.y.
julia> import MyModule.x; x()
"x"
julia> x(a)=1
x (generic function with 2 methods)
julia> y() #MyModule.y not available
ERROR: UndefVarError: y not defined
julia> y()=2 #Define a new function
y (generic function with 1 method)
Hello Jiahao,
I thought that after importing only a function from a module, rest of
the functions (that are exported by the module) should be inaccessible. Also,
functions not exported will remain inaccessible always.
~~~
julia> versioninfo()
Julia Version 0.3.3
Commit b24213b (2014-11-23 20:19 UTC)
Platform Info:
System: Linux (x86_64-unknown-linux-gnu)
CPU: Intel(R) Core(TM) i3 CPU M 380 @ 2.53GHz
WORD_SIZE: 64
BLAS: libblas
LAPACK: liblapack
LIBM: libm
LLVM: libLLVM-3.3
julia> import MyModule.x; x()
"x"
julia> p() # Not available in the current namespace, but
ERROR: p not defined
julia> MyModule.p() # a private function (that is not exported by MyModule)
is available.
"p"
julia> MyModule.p(a::Int64)=1; MyModule.p(3) # Overloading...
1
julia> y() # Not available in the current namespace
ERROR: y not defined
julia> MyModule.y() # But still available by referencing. This seems to be a
feature which was counter intuitive for me.
"y"
~~~
So after reading the manual, I got the wrong impression. Perhaps this snippet might be
added to the manual, and may be useful for complete beginners.
Cheers,
Devendra