How it works...
In Julia, there are two types of scope—global scope and local scope. In the Julia command line, variables are created in the global scope by default, while in functions the variables are created in local scopes. This means that if you want to copy the body of a Julia function to the Julia command line (for example, for testing), you have to surround it with a let...end block. Otherwise, your code in the Julia command line will resolve variables differently compared with the code inside a Julia function.
It is important to note that within a local scope (such as for or while) the global variables by default are only available for reading but not for assignment (more precisely whenever you try to assign a value to a global variable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access