Reputation: 146
I have a module containing a number of mathematical and physical constants. As it stands, I am able to access the variables through namespacing:
module Constant
export c
const c = 299792458 # m/s
end
include("constants.jl")
println(Constant.c) # 299792458
However, I am looking to access the module variables as local variables e.g. E=m*c^2
;
include("constants.jl")
"""
something here
"""
println(c) # 299792458
I assume that in order to achieve this I need to implement either using
or import
, however in both scenarios I get error
ERROR: LoadError: ArgumentError: Package Constant not found in current path:
- Run `import Pkg; Pkg.add("Constant")` to install the Constant package.
Adding this to the ideal.jl
code does not solve the problem:
include("constants.jl")
import Pkg
Pkg.add("Constant")
import Constant
println(c)
which fails with error
ERROR: LoadError: The following package names could not be resolved:
* Constant (not found in project, manifest or registry)
Please specify by known `name=uuid`.
How do I go about resolving this?
P.S. I am aware that the current naming convention is not ideal - this is not set in stone and may change at a later date. I am using Julia v1.0.2:
$ julia -v
julia version 1.0.2
Upvotes: 2
Views: 243