Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module name clashes with exported type in Julia

Tags:

module

julia

I happen to make a silly mistake - to create a type which has the name of the module it is in. Suppose that I want to export that type X from my package X:

module X

export X
export .X
export X.X

type X end

end

First would give me:

ERROR: LoadError: LoadError: invalid redefinition of constant X

Second:

ERROR: LoadError: LoadError: syntax: invalid identifier name "."

Third:

ERROR: LoadError: LoadError: syntax: extra token "." after end of expression

is there a valid syntax to solve my export problem?

P.S. I know that I could just change name for module/type.

like image 330
Artem Oboturov Avatar asked May 05 '16 17:05

Artem Oboturov


People also ask

How do I import a module into Julia?

To load a module from a package, the statement using ModuleName can be used. To load a module from a locally defined module, a dot needs to be added before the module name like using . ModuleName .

What is the difference between import and using in Julia?

My guess based on reading the docs: using is used to bring another module into the name-space of the current module. import is used to bring specific types/functions/variables from other modules into the name-space of the current module.

What does Julia include?

Julia has two mechanisms for loading code: Code inclusion: e.g. include("source. jl") . Inclusion allows you to split a single program across multiple source files.


1 Answers

As Tom Breloff said, there is the well-followed practice for naming packages that implement a new type. If your package exports a type that supports very fast operations on very small strings, and that type is named FastString, the recommended package name is FastStrings.jl.

Julia package names include the .jl suffix .. so should yours. For projects that pull multiple packages together under one umbrella, the project name may forgo the trailing .jl; the packages it brings together should end with .jl.

Some guidelines for naming packages are gathered here

like image 92
Jeffrey Sarnoff Avatar answered Oct 16 '22 01:10

Jeffrey Sarnoff