Scope modifiers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 703: | Line 703: | ||
A named function definition (<code>function foo() { ... }</code>) is “hoisted” to the top of the enclosing function; it is therefore possible to call a function before its definition would seem to be executed. |
A named function definition (<code>function foo() { ... }</code>) is “hoisted” to the top of the enclosing function; it is therefore possible to call a function before its definition would seem to be executed. |
||
=={{header|jq}}== |
|||
jq uses lexical scoping. |
|||
Variables defined on the command-line have global scope |
|||
but are hidden by the rules of lexical scoping. |
|||
Local scope is introduced by function declarations (including declarations of inner functions) |
|||
and by variable assignments, i.e. by `def` and `as` statements. |
|||
Example: |
|||
<pre> |
|||
jq -nc --arg x a ' |
|||
def a($x): |
|||
def b($x): 1 as $x | $x; |
|||
$x, b(10)]; |
|||
[$x, a(0)]' |
|||
</pre> |
|||
{{Output}} |
|||
<pre> |
|||
["a",[0,1]] |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |