September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,33 +0,0 @@
|
|||
var1$ = "Global1"
|
||||
var2$ = "Global2"
|
||||
|
||||
PRINT "Before function call:"
|
||||
PRINT "var1$ = """ var1$ """"
|
||||
PRINT "var2$ = """ var2$ """"
|
||||
|
||||
PROCtestscope(var1$)
|
||||
PROCtestscope(var1$)
|
||||
|
||||
PRINT "After function call:"
|
||||
PRINT "var1$ = """ var1$ """"
|
||||
PRINT "var2$ = """ var2$ """"
|
||||
END
|
||||
|
||||
DEF PROCtestscope(var2$)
|
||||
PRINT "On entry to function:"
|
||||
PRINT "var1$ = """ var1$ """"
|
||||
PRINT "var2$ = """ var2$ """"
|
||||
|
||||
LOCAL var1$
|
||||
PRIVATE var2$
|
||||
PRINT "After LOCAL/PRIVATE:"
|
||||
PRINT "var1$ = """ var1$ """"
|
||||
PRINT "var2$ = """ var2$ """"
|
||||
|
||||
var1$ = "Local"
|
||||
var2$ = "Private"
|
||||
PRINT "After assignments:"
|
||||
PRINT "var1$ = """ var1$ """"
|
||||
PRINT "var2$ = """ var2$ """"
|
||||
|
||||
ENDPROC
|
||||
40
Task/Scope-modifiers/Bc/scope-modifiers.bc
Normal file
40
Task/Scope-modifiers/Bc/scope-modifiers.bc
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
define g(a) {
|
||||
auto b
|
||||
|
||||
b = 3
|
||||
|
||||
"Inside g: a = "; a
|
||||
"Inside g: b = "; b
|
||||
"Inside g: c = "; c
|
||||
"Inside g: d = "; d
|
||||
|
||||
a = 3; b = 3; c = 3; d = 3
|
||||
}
|
||||
|
||||
define f(a) {
|
||||
auto b, c
|
||||
|
||||
b = 2; c = 2
|
||||
"Inside f (before call): a = "; a
|
||||
"Inside f (before call): b = "; b
|
||||
"Inside f (before call): c = "; c
|
||||
"Inside f (before call): d = "; d
|
||||
x = g(2) /* Assignment prevents output of the return value */
|
||||
"Inside f (after call): a = "; a
|
||||
"Inside f (after call): b = "; b
|
||||
"Inside f (after call): c = "; c
|
||||
"Inside f (after call): d = "; d
|
||||
|
||||
a = 2; b = 2; c = 2; d = 2
|
||||
}
|
||||
|
||||
a = 1; b = 1; c = 1; d = 1
|
||||
"Global scope (before call): a = "; a
|
||||
"Global scope (before call): b = "; b
|
||||
"Global scope (before call): c = "; c
|
||||
"Global scope (before call): d = "; d
|
||||
x = f(1)
|
||||
"Global scope (before call): a = "; a
|
||||
"Global scope (before call): b = "; b
|
||||
"Global scope (before call): c = "; c
|
||||
"Global scope (before call): d = "; d
|
||||
13
Task/Scope-modifiers/C-sharp/scope-modifiers-1.cs
Normal file
13
Task/Scope-modifiers/C-sharp/scope-modifiers-1.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
public //visible to anything.
|
||||
protected //visible to current class and to derived classes.
|
||||
internal //visible to anything inside the same assembly (.dll/.exe).
|
||||
protected internal //visible to anything inside the same assembly and also to derived classes outside the assembly.
|
||||
private //visible only to the current class.
|
||||
|
||||
//Modifier | Class | Assembly | Subclass | World
|
||||
//--------------------------------------------------------
|
||||
//public | Y | Y | Y | Y
|
||||
//protected internal | Y | Y | Y | N
|
||||
//protected | Y | N | Y | N
|
||||
//internal | Y | Y | N | N
|
||||
//private | Y | N | N | N
|
||||
21
Task/Scope-modifiers/C-sharp/scope-modifiers-2.cs
Normal file
21
Task/Scope-modifiers/C-sharp/scope-modifiers-2.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
public interface IPrinter
|
||||
{
|
||||
void Print();
|
||||
}
|
||||
|
||||
public class IntPrinter : IPrinter
|
||||
{
|
||||
void IPrinter.Print() { // explicit implementation
|
||||
Console.WriteLine(123);
|
||||
}
|
||||
|
||||
public static void Main() {
|
||||
//====Error====
|
||||
IntPrinter p = new IntPrinter();
|
||||
p.Print();
|
||||
|
||||
//====Valid====
|
||||
IPrinter p = new IntPrinter();
|
||||
p.Print();
|
||||
}
|
||||
}
|
||||
22
Task/Scope-modifiers/Kotlin/scope-modifiers.kotlin
Normal file
22
Task/Scope-modifiers/Kotlin/scope-modifiers.kotlin
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// version 1.1.2
|
||||
|
||||
class SomeClass {
|
||||
val id: Int
|
||||
|
||||
companion object {
|
||||
private var lastId = 0
|
||||
val objectsCreated get() = lastId
|
||||
}
|
||||
|
||||
init {
|
||||
id = ++lastId
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val sc1 = SomeClass()
|
||||
val sc2 = SomeClass()
|
||||
println(sc1.id)
|
||||
println(sc2.id)
|
||||
println(SomeClass.objectsCreated)
|
||||
}
|
||||
10
Task/Scope-modifiers/Phix/scope-modifiers-1.phix
Normal file
10
Task/Scope-modifiers/Phix/scope-modifiers-1.phix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
forward function localf() -- not normally necesssary, but will not harm
|
||||
forward global function globalf() -- ""
|
||||
|
||||
function localf()
|
||||
return 1
|
||||
end function
|
||||
|
||||
global function globalf()
|
||||
return 2
|
||||
end function
|
||||
5
Task/Scope-modifiers/Phix/scope-modifiers-2.phix
Normal file
5
Task/Scope-modifiers/Phix/scope-modifiers-2.phix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
include somefile.e as xxx
|
||||
-- alternatively, within somefile.e:
|
||||
namespace xxx -- (only supported in Phix for compatibility with OpenEuphoria)
|
||||
|
||||
res = xxx:globalf() -- call a global function named globalf, specifically the one declared in somefile.e
|
||||
Loading…
Add table
Add a link
Reference in a new issue