Scope/Function names and labels: Difference between revisions

m
no edit summary
(Added Kotlin)
mNo edit summary
Line 435:
def M(x): if x == 1 then F(x) else 2 end;</lang>
If F and M are not required to be top-level functions, then both F and M could be defined as inner functions of the same enclosing function.
 
=={{header|Julia}}==
In Julia, there is one type of global scope, defined as the scope of the individual module
(there is no global scope above module scope). User code not defined within a specific
module has global scope within the predefined default module main.
<br />
There are two types of local or nonglobal scope in Julia:
hard local scope, which is the scope of variables defined within functions, and the
"soft" local scope of variables within code structures, as quoted below from Julia's documentation:
<pre>
Type of scope | block/construct introducing this kind of scope
----------------------------------------------------------------
Global Scope | module, baremodule, at interactive prompt (REPL)
Local Scope | Soft Local Scope: for, while, comprehensions, try-catch-finally, let
Local Scope | Hard Local Scope: functions (either syntax, anonymous & do-blocks), struct, macro
</pre>
Hard local scope means that a variable defined within a function defaults to being local to
the function unless this is overridden with the <code>global</code> keyword which allows
such a variable to reference a module-level global variable. Soft local scope means that variables
within such a code block reference variables of the same name in the parent scope unless the
variable is explicitly declared to be local with the <code>local</code> keyword.
<br />
Julia uses lexical scoping, so the scope of a variable as defined above can be
determined just by looking at the code where the variable was defined.
 
=={{header|Kotlin}}==
4,105

edits