Multiple errors -- "premature end of input" and "misplaced expression"



I am using Julia 0.6 and running in Juno. All packages are up-to-date.

I am getting ‘syntax: incomplete: premature end of imput’ and ‘unsupported or misplaced expression “using” in function’ errors.

I have no problems with the following code:

using Plots

t = 0:.1:100;
plot(t, sin.(t))

I can run it or press shift+enter after each line and it produces the expected results.

However, when I try to turn it into a function like so:

function PlotSin()
using Plots

t = 0:.1:100;
plot(t, sin.(t))

I get the “premature end of input” error after the function delcaration (when using shift+enter). Next, if I try to call it in the console, I get the “misplaced expression” error.

I’ve tried this for a few other sample bits of code and the same thing happens—the code runs fine until I try to turn it into a function.

As I’m new to Julia, I could use a hand to figure out what’s going on.



using belongs at the top level (outside the function declaration). This code would generate a warning in the Julia REPL, but Juno is probably doing some light pre-parsing to find function boundaries and may not fully handle this case.


Thanks! This did the trick.

Just for reference, I had to start with a clean file before I could get it to work. Modifying the original produced the same errors.