Hi,
Iβve been trying to get back to basics after being away from Julia for quite a while and I am struggling with some basic concepts, as it seems.
My question is, when I am using Revise and Packages does the function documentation also get updated? I see something which I believe is inconsistency but it could also be just my misunderstanding.
Here is my example. I have written the following function in a file named "AR_functions.jl"
( I deleted parts of the code to make the example short, they arenβt important)
"""
mlag(X::Array,p::Int64; cnst=1)
Creates a lagged matrix of X with p lags.
Returns **Xlag** and **Y**, such that size(Xlag,1) = T-p and **Y** = X[p+1:end,:]
Adds a constant to the last column by default, can be disabled by cnst=0.
"""
function mlag(X::Array,p::Int64; cnst=1)
...
end
Then, if I have in my main file
using Revise
includet("AR_functions.jl")
After typing mlag
I get
mlag (generic function with 1 method)
and I get the documentation printed in the REPL with the β?β sign:
help?> mlag
search: mlag muladd similar accumulate accumulate! @atomicreplace maxintfloat
(Xlag,Y) = mlag(X::Array,p::Int64; cnst=1)
Creates a lagged matrix of X with p lags.
Returns Xlag and Y, such that size(Xlag,1) = T-p and Y = X[p+1:end,:]
Adds a constant to the last column by default, can be disabled by cnst=0.
If I change the function above by specifying the Float64
"""
mlag(X::Array{Float64},p::Int64; cnst=1)
"""
function mlag(X::Array{Float64},p::Int64; cnst=1)
and again rerun the includet and type mlag
in the REPL get generic function with 2 methods, and if I type ?mlag
I get the two methods:
help?> mlag
search: mlag muladd similar accumulate accumulate! @atomicreplace maxintfloat
(Xlag,Y) = mlag(X::Array,p::Int64; cnst=1)
Creates a lagged matrix of X with p lags.
Returns Xlag and Y, such that size(Xlag,1) = T-p and Y = X[p+1:end,:]
Adds a constant to the last column by default, can be disabled by cnst=0.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
(Xlag,Y) = mlag(X::Array{Float64},p::Int64; cnst=1)
Creates a lagged matrix of X with p lags.
Returns Xlag and Y, such that size(Xlag,1) = T-p and Y = X[p+1:end,:]
Adds a constant to the last column by default, can be disabled by cnst=0.
So far so good, I added a second method. Now, for me, I want to stay with only one of the methods, because I am trying things out but I donβt want to restart Julia all the time. So after reading the documentation and the forums I realized that packages&Revise should do the trick. So I followed this and created MyPkg which includes the following code, simply βexportβ and then the first function simply pasted from the other file
module MyPkg
export mlag, ols
# Write your package code here.
"""
(Xlag,Y) = mlag(X::Array,p::Int64; cnst=1)
"""
function mlag(X::Array,p::Int64; cnst=1)
....
end
which I then add to my code using
using Revise
using MyPkg
and running the same statements mlag
and ?mlag
result in Julia telling me I have a function with 1 method and the docs, respectively.
Here is the weird part
If I go through and make the same change above (adding βFloat64β to the function and to the docs), when I get a discrepancy. I now get 1 method, but have both documentations as if it has 2
julia> mlag
mlag (generic function with 1 method)
help?> mlag
search: mlag muladd similar accumulate accumulate! @atomicreplace maxintfloat
(Xlag,Y) = mlag(X::Array,p::Int64; cnst=1)
Creates a lagged matrix of X with p lags.
Returns Xlag and Y, such that size(Xlag,1) = T-p and Y = X[p+1:end,:]
Adds a constant to the last column by default, can be disabled by cnst=0.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
(Xlag,Y) = mlag(X::Array{Float64},p::Int64; cnst=1)
Creates a lagged matrix of X with p lags.
Returns Xlag and Y, such that size(Xlag,1) = T-p and Y = X[p+1:end,:]
Adds a constant to the last column by default, can be disabled by cnst=0.
It says 1 method but gives me two documentations. Is this normal? Can I be sure that the function is now updated?
And finally, is there a better way for development without having to restart Julia?
Thanks!