Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
47
Task/Scope-modifiers/AWK/scope-modifiers.awk
Normal file
47
Task/Scope-modifiers/AWK/scope-modifiers.awk
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# syntax: GAWK -f SCOPE_MODIFIERS.AWK
|
||||
BEGIN {
|
||||
# All variables in AWK are considered global
|
||||
a = 1 # global
|
||||
b = 2 # global
|
||||
# c is undefined
|
||||
#
|
||||
x(a) # call function in default namespace
|
||||
printf("a='%s' c='%s'\n\n",a,c)
|
||||
#
|
||||
# A recent addition to GAWK is namespace
|
||||
# The default namespace is "awk"
|
||||
#
|
||||
# All variables in the default namespace may be referenced by
|
||||
# name or awk::name
|
||||
#
|
||||
# All variables in another namespace must be referenced as
|
||||
# namespace::name
|
||||
#
|
||||
# For example to reference function x in the default namespace use
|
||||
# x() or awk::x()
|
||||
#
|
||||
# To reference function x in the "test" namespace use test::x()
|
||||
#
|
||||
# Let's test the two functions named "x" which are shown below
|
||||
#
|
||||
awk::x(22) # call function in default namespace
|
||||
printf("a='%s' c='%s'\n\n",a,c)
|
||||
test::x(22) # call function in another namespace
|
||||
printf("a='%s' c='%s'\n\n",a,c)
|
||||
exit(0)
|
||||
}
|
||||
# Variables are:
|
||||
# - local to functions when specified as arguments
|
||||
# - passed by value except arrays which are passed by reference
|
||||
#
|
||||
function x(a, c) {
|
||||
printf("inside awk::x() a='%s'\n",a)
|
||||
a = c = 9
|
||||
printf("inside awk::x() a='%s'\n",a)
|
||||
}
|
||||
@namespace "test"
|
||||
function x(a, c) {
|
||||
printf("inside test::x() a='%s'\n",a)
|
||||
a = c = 9
|
||||
printf("inside test::x() a='%s'\n",a)
|
||||
}
|
||||
5
Task/Scope-modifiers/Ada/scope-modifiers-1.adb
Normal file
5
Task/Scope-modifiers/Ada/scope-modifiers-1.adb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package P is
|
||||
... -- Declarations placed here are publicly visible
|
||||
private
|
||||
... -- These declarations are visible only to the children of P
|
||||
end P;
|
||||
11
Task/Scope-modifiers/Ada/scope-modifiers-2.adb
Normal file
11
Task/Scope-modifiers/Ada/scope-modifiers-2.adb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package P is
|
||||
type T is private; -- No components visible
|
||||
procedure F (X : in out T); -- The only visible operation
|
||||
N : constant T; -- A constant, which value is hidden
|
||||
private
|
||||
type T is record -- The implementation, visible to children only
|
||||
Component : Integer;
|
||||
end record;
|
||||
procedure V (X : in out T); -- Operation used only by children
|
||||
N : constant T := (Component => 0); -- Constant implementation
|
||||
end P;
|
||||
4
Task/Scope-modifiers/Ada/scope-modifiers-3.adb
Normal file
4
Task/Scope-modifiers/Ada/scope-modifiers-3.adb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
package body P is
|
||||
-- The implementation of P, invisible to anybody
|
||||
procedure W (X : in out T); -- Operation used only internally
|
||||
end P;
|
||||
5
Task/Scope-modifiers/Ada/scope-modifiers-4.adb
Normal file
5
Task/Scope-modifiers/Ada/scope-modifiers-4.adb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
private package P.Q is
|
||||
... -- Visible to the siblings only
|
||||
private
|
||||
... -- Visible to the children only
|
||||
end P.Q;
|
||||
16
Task/Scope-modifiers/Oberon-07/scope-modifiers-1.oberon
Normal file
16
Task/Scope-modifiers/Oberon-07/scope-modifiers-1.oberon
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
MODULE D1;
|
||||
VAR x* : INTEGER (* x is visible (read-only) in other modules *)
|
||||
y, z : BOOLEAN; (* y and z are not visible to other modules *)
|
||||
PROCEDURE P1*; (* P1 can be called from other modules *)
|
||||
VAR lv1, lv2 : INTEGER;
|
||||
PROCEDURE Sub1;
|
||||
BEGIN (* Sub1 body *)
|
||||
(* lv1, lv2 not visible here *)
|
||||
END Sub1;
|
||||
BEGIN (* P1 body *)
|
||||
(* x, y, z, lv1, lv2 and Sub1 visible here *)
|
||||
END P1;
|
||||
|
||||
BEGIN (* D1 body *)
|
||||
(* x, y, z and P1 visible here *)
|
||||
END D1.
|
||||
6
Task/Scope-modifiers/Oberon-07/scope-modifiers-2.oberon
Normal file
6
Task/Scope-modifiers/Oberon-07/scope-modifiers-2.oberon
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
MODULE U1;
|
||||
IMPORT D1;
|
||||
VAR v1, v2 : INTEGER;
|
||||
BEGIN
|
||||
(* as well as v1 and v2, D1.x and D1.P1 are visible here *)
|
||||
END U1.
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
-->
|
||||
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">localf</span><span style="color: #0000FF;">()</span> <span style="color: #000080;font-style:italic;">-- not normally necesssary, but will not harm</span>
|
||||
<span style="color: #008080;">forward</span> <span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">globalf</span><span style="color: #0000FF;">()</span> <span style="color: #000080;font-style:italic;">-- ""</span>
|
||||
forward function localf() -- not normally necesssary, but will not harm
|
||||
forward global function globalf() -- ""
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">localf</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function localf()
|
||||
return 1
|
||||
end function
|
||||
|
||||
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">globalf</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">2</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
<!--
|
||||
global function globalf()
|
||||
return 2
|
||||
end function
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
-->
|
||||
<span style="color: #008080;">include</span> <span style="color: #000000;">somefile</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> <span style="color: #000000;">as</span> <span style="color: #000000;">xxx</span>
|
||||
<span style="color: #000080;font-style:italic;">-- alternatively, within somefile.e:</span>
|
||||
<span style="color: #7060A8;">namespace</span> <span style="color: #000000;">xxx</span> <span style="color: #000080;font-style:italic;">-- (only supported in Phix for compatibility with OpenEuphoria)</span>
|
||||
include somefile.e as xxx
|
||||
-- alternatively, within somefile.e:
|
||||
namespace xxx -- (only supported in Phix for compatibility with Euphoria)
|
||||
|
||||
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">xxx</span><span style="color: #0000FF;">:</span><span style="color: #000000;">globalf</span><span style="color: #0000FF;">()</span> <span style="color: #000080;font-style:italic;">-- call a global function named globalf, specifically the one declared in somefile.e</span>
|
||||
<!--
|
||||
res = xxx:globalf() -- call a global function named globalf, specifically the one declared in somefile.e
|
||||
|
|
|
|||
6
Task/Scope-modifiers/PowerShell/scope-modifiers.ps1
Normal file
6
Task/Scope-modifiers/PowerShell/scope-modifiers.ps1
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
$a = "foo" # global scope
|
||||
function test {
|
||||
$a = "bar" # local scope
|
||||
Write-Host Local: $a # "bar" - local variable
|
||||
Write-Host Global: $global:a # "foo" - global variable
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue