UndefVarError: linspace not defined

New to julia 1.0, I am running some examples and got the following errors, do you have any ideas how to solve this?
Thanks.

‘’’
julia> linspace(0,2*pi,10)
ERROR: UndefVarError: linspace not defined
Stacktrace:
[1] top-level scope at none:0
‘’’

5 Likes

Linspace was deprecated. You should be able to use

range(0,stop=2*pi,length=10)
14 Likes

Worked!
Thank you very much.
BTW, where could I find the information about whether a specific function is deprecated or not?
For “linspace”, I googled a lot before posting here, however I was failed to find any information about this.

If you run the code with Julia v0.7 it will print a deprecation warning.

1 Like

Even more readable with unicode :slight_smile:

range(0, stop=2π, length=10)
3 Likes

Then, if linspace is deprecated, please update the documentation at

https://julialang.org/downloads/plotting.html

It is very frustrating when you are a new user, you pick an example from a tutorial and it doesn’t work! I would suggest to try not to break old code.

5 Likes

Good catch! The code is here https://github.com/JuliaLang/www.julialang.org/blob/9f544a5476c74a74d7dfb1f15e939550e5dd851e/downloads/plotting.html, care to make a pull request?

2 Likes

Not OP, but this should do the trick. Looks like it just slipped through the cracks.

Seelengrab did it faster than myself!

Just a question, is there any particular reason why stop became a named argument? It seems antisymmetric with the start argument.
Be able to use as range(start, stop) would be nice.

1 Like

https://github.com/JuliaLang/julia/pull/28708

In Julia v1.1 it will be the exactly the way you want. Until then, if you use Compat.jl with the current versions of Julia, you can use the new notation as soon as https://github.com/JuliaLang/Compat.jl/pull/633 is merged

2 Likes

This is the correct answer.

But, being required to maintain a Julia v0.7 installation just to learn about a deprecated function is kind of a pain, even for people experienced with Julia. In practice, examples using linspace etc. will be around for some time, and will continue to cause confusion.

I’m just pointing it out. Not complaining about it. It has not bothered me enough to try to find a solution myself.

In practice, examples using linspace etc. will be around for some time, and will continue to cause confusion.

Gotta catch them all? Here are a few examples to start your collection off…

1 Like

Maybe admit an error and get that function name back?

All (or almost) of the decisions to make deprecations and replacements were discussed thoroughly over a long period and were made for good reasons.

2 Likes

Sorry for digressing a bit from the OP, but I had this issue today as the convolution function from Julia 0.6 (conv) is not in Julia 1.0 and I could not find it in any of the release notes for 0.7/1.0.

In the end I went back to my 0.7 installation to try and get an informative warning message (it told me that conv had been moved to DSP.jl.

Is there somewhere with a more comprehensive list of deprecations than the release notes? Or if people find these should they submit a PR to change the 0.7 release note? Thanks

I’ve been having the same problem, not just with linspace but with conv as well.

As a new user this makes the language feel quite opaque, especially since the latest version of julia will throw a generic error message when trying to run simple example code from a few versions ago.

A better situation might be that when julia tries to call a known depreciated function, an error message is thrown detailing the version in which this function was depreciated, and the function that inherited it’s functionality along with the new syntax

If we can find a comprehensive list of depreciations this shouldn’t be so hard to implement, and It would work wonders for the accessibility of the language.

1 Like

Yes, it’s called Julia 0.7.

1 Like

I understand that this syntax: x = linspace(0, 5) should be replaced by something like range(0,stop=5) ? How should the syntax be in this simple example?

You would need to give a length or a step, eg

range(0; stop = 5, step = 1)

which can be written as 0:5 of course.

Note that when 1.1 comes out, you will be able to write

range(0, 5; step = 1)