Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

sorry - why would you expect a local declaration to be in scope for other code?

s is defined in the statement and then is undefined out of that statement because there is no other scope for it - it's at top level. just write s =0 and all is well as s exist in the global scope where your code lives as well...



OP should've written just `s=0`, yes. Because showcases their complaint better since, although works in REPL, also fails when in file. (It's also the example given in docs[1].) Now, it looks like they tried to make it fail.

[1]: https://docs.julialang.org/en/v1/manual/variables-and-scopin...


Shouldn't the language flag that using local in that scope is an error then?


Yes - the error reporting has always been one of my complaints about Julia (although it's hugely improved). I think that the Julia dev community are really really interested in cool language features and optimisations but much less empathic with numpties like me that can't understand why their code crashes. More work on this would be much better.

Although it's a bit of an challenge to get the interpreter to understand which thing that's out of scope should be in scope for the code to work (because it's all out of scope..)



well done that man




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: