September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
13
Task/Classes/Crystal/classes.crystal
Normal file
13
Task/Classes/Crystal/classes.crystal
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class MyClass
|
||||
|
||||
def initialize
|
||||
@instance_var = 0
|
||||
end
|
||||
|
||||
def add_1
|
||||
@instance_var += 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
my_class = MyClass.new
|
||||
1
Task/Classes/DM/classes-1.dm
Normal file
1
Task/Classes/DM/classes-1.dm
Normal file
|
|
@ -0,0 +1 @@
|
|||
s
|
||||
22
Task/Classes/DM/classes-2.dm
Normal file
22
Task/Classes/DM/classes-2.dm
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Declare the class "/foo"
|
||||
foo
|
||||
// Everything inside the indented block is relative to the parent, "/foo" here.
|
||||
// Instance variable "bar", with a default value of 0
|
||||
// Here, var/bar is relative to /foo, thus it becomes "/foo/var/bar" ultimately.
|
||||
var/bar = 0
|
||||
|
||||
// The "New" proc is the constructor.
|
||||
New()
|
||||
// Constructor code.
|
||||
|
||||
// Declares a proc called "Baz" on /foo
|
||||
proc/baz()
|
||||
// Do things.
|
||||
|
||||
// Instantiation code.
|
||||
// Overriding /client/New() means it is ran when a client connects.
|
||||
/client/New()
|
||||
..()
|
||||
var/foo/x = new /foo()
|
||||
x.bar = 10 // Assign to the instance variable.
|
||||
x.baz() // Call "baz" on our instance.
|
||||
|
|
@ -1,30 +1,27 @@
|
|||
#import system.
|
||||
#import extensions.
|
||||
import extensions.
|
||||
|
||||
#class MyClass
|
||||
class MyClass
|
||||
{
|
||||
#field _variable.
|
||||
object prop Variable :: _variable.
|
||||
|
||||
#method Variable = _variable.
|
||||
|
||||
#method someMethod
|
||||
someMethod
|
||||
[
|
||||
_variable := 1.
|
||||
]
|
||||
|
||||
#constructor new
|
||||
constructor new
|
||||
[
|
||||
]
|
||||
}
|
||||
|
||||
#symbol program =
|
||||
program =
|
||||
[
|
||||
// instantiate the class
|
||||
#var instance := MyClass new.
|
||||
var instance := MyClass new.
|
||||
|
||||
// invoke the method
|
||||
instance someMethod.
|
||||
|
||||
// get the variable
|
||||
console writeLine:"Variable=":(instance Variable).
|
||||
console printLine("Variable=",instance Variable).
|
||||
].
|
||||
|
|
|
|||
8
Task/Classes/Kotlin/classes.kotlin
Normal file
8
Task/Classes/Kotlin/classes.kotlin
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class MyClass(val myInt: Int) {
|
||||
fun treble(): Int = myInt * 3
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val mc = MyClass(24)
|
||||
print("${mc.myInt}, ${mc.treble()}")
|
||||
}
|
||||
29
Task/Classes/OoRexx/classes.rexx
Normal file
29
Task/Classes/OoRexx/classes.rexx
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
p = .point~new
|
||||
c = .circle~new
|
||||
|
||||
p~print
|
||||
c~print
|
||||
|
||||
::class point
|
||||
::method init
|
||||
expose x y
|
||||
use strict arg x = 0, y = 0 -- defaults to 0 for any non-specified coordinates
|
||||
|
||||
::attribute x
|
||||
::attribute y
|
||||
|
||||
::method print
|
||||
expose x y
|
||||
say "A point at location ("||x","y")"
|
||||
|
||||
::class circle subclass point
|
||||
::method init
|
||||
expose radius
|
||||
use strict arg x = 0, y = 0, radius = 0
|
||||
self~init:super(x, y) -- call superclass constructor
|
||||
|
||||
::attribute radius
|
||||
|
||||
::method print
|
||||
expose radius
|
||||
say "A circle of radius" radius "centered at location ("||self~x","self~y")"
|
||||
30
Task/Classes/Rust/classes.rust
Normal file
30
Task/Classes/Rust/classes.rust
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
struct MyClass {
|
||||
variable: i32, // member variable = instance variable
|
||||
}
|
||||
|
||||
impl MyClass {
|
||||
// member function = method, with its implementation
|
||||
fn some_method(&mut self) {
|
||||
self.variable = 1;
|
||||
}
|
||||
|
||||
// constructor, with its implementation
|
||||
fn new() -> MyClass {
|
||||
// Here could be more code.
|
||||
MyClass { variable: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
fn main () {
|
||||
// Create an instance in the stack.
|
||||
let mut instance = MyClass::new();
|
||||
|
||||
// Create an instance in the heap.
|
||||
let mut p_instance = Box::<_>::new(MyClass::new());
|
||||
|
||||
// Invoke method on both istances,
|
||||
instance.some_method();
|
||||
p_instance.some_method();
|
||||
|
||||
// Both instances are automatically deleted when their scope ends.
|
||||
}
|
||||
10
Task/Classes/Zkl/classes-1.zkl
Normal file
10
Task/Classes/Zkl/classes-1.zkl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
class C{ // define class named "C", no parents or attributes
|
||||
println("starting construction"); // all code outside functions is wrapped into the constructor
|
||||
var v; // instance data for this class
|
||||
fcn init(x) // initializer for this class, calls constructor
|
||||
{ v = x }
|
||||
println("ending construction of ",self);
|
||||
}
|
||||
c1:=C(5); // create a new instance of C
|
||||
c2:=c1("hoho"); // create another instance of C
|
||||
println(C.v," ",c1.v," ",c2.v);
|
||||
3
Task/Classes/Zkl/classes-2.zkl
Normal file
3
Task/Classes/Zkl/classes-2.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
C.__constructor(); // run base class constructor for giggles
|
||||
C.init(456); // initialize base class without creating instance
|
||||
println(C.v," ",c1.v);
|
||||
Loading…
Add table
Add a link
Reference in a new issue