Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
9
Task/Classes/Ada/classes-1.adb
Normal file
9
Task/Classes/Ada/classes-1.adb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package My_Package is
|
||||
type My_Type is tagged private;
|
||||
procedure Some_Procedure(Item : out My_Type);
|
||||
function Set(Value : in Integer) return My_Type;
|
||||
private
|
||||
type My_Type is tagged record
|
||||
Variable : Integer := -12;
|
||||
end record;
|
||||
end My_Package;
|
||||
13
Task/Classes/Ada/classes-2.adb
Normal file
13
Task/Classes/Ada/classes-2.adb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package body My_Package is
|
||||
procedure Some_Procedure(Item : out My_Type) is
|
||||
begin
|
||||
Item := 2 * Item;
|
||||
end Some_Procedure;
|
||||
|
||||
function Set(Value : Integer) return My_Type is
|
||||
Temp : My_Type;
|
||||
begin
|
||||
Temp.Variable := Value;
|
||||
return Temp;
|
||||
end Set;
|
||||
end My_Package;
|
||||
8
Task/Classes/Ada/classes-3.adb
Normal file
8
Task/Classes/Ada/classes-3.adb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
with My_Package; use My_Package;
|
||||
|
||||
procedure Main is
|
||||
Foo : My_Type; -- Foo is created and initialized to -12
|
||||
begin
|
||||
Some_Procedure(Foo); -- Foo is doubled
|
||||
Foo := Set(2007); -- Foo.Variable is set to 2007
|
||||
end Main;
|
||||
66
Task/Classes/COBOL/classes.cob
Normal file
66
Task/Classes/COBOL/classes.cob
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
CLASS-ID. my-class INHERITS base.
|
||||
|
||||
*> The 'INHERITS base' and the following ENVIRONMENT DIVISION
|
||||
*> are optional (in Visual COBOL).
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
CLASS base.
|
||||
|
||||
*> There is no way (as far as I can tell) of creating a
|
||||
*> constructor. However, you could wrap it with another
|
||||
*> method to achieve the desired effect.
|
||||
*>...
|
||||
|
||||
OBJECT.
|
||||
*> Instance data
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 instance-variable PIC 9(8).
|
||||
|
||||
*> Properties can have getters and setters automatically
|
||||
*> generated.
|
||||
01 a-property PIC 9(8) PROPERTY.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
METHOD-ID. some-method.
|
||||
PROCEDURE DIVISION.
|
||||
*> ...
|
||||
END METHOD some-method.
|
||||
END OBJECT.
|
||||
END CLASS my-class.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. example-class-use.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
*> These declarations brings the class and property into
|
||||
*> scope.
|
||||
CLASS my-class
|
||||
PROPERTY a-property.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
*> Declaring a my-class reference variable.
|
||||
01 instance USAGE OBJECT REFERENCE my-class.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
*> Invoking a static method or (in this case) a constructor.
|
||||
INVOKE my-class "new" RETURNING instance
|
||||
|
||||
*> Invoking an instance method.
|
||||
INVOKE instance "some-method"
|
||||
|
||||
*> Using the setter and getter of a-property.
|
||||
MOVE 5 TO a-property OF instance
|
||||
DISPLAY a-property OF instance
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
||||
END PROGRAM example-class-use.
|
||||
14
Task/Classes/Haxe/classes-1.hx
Normal file
14
Task/Classes/Haxe/classes-1.hx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class BasicClass {
|
||||
public function basicMethod():Void {
|
||||
return;
|
||||
}
|
||||
|
||||
public function new() {}
|
||||
}
|
||||
|
||||
class Main {
|
||||
static public function main():Void {
|
||||
var basic_object = new BasicClass();
|
||||
$type(basic_object);
|
||||
}
|
||||
}
|
||||
21
Task/Classes/Haxe/classes-2.hx
Normal file
21
Task/Classes/Haxe/classes-2.hx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class Example (x) # 'x' is a field in class
|
||||
|
||||
# method definition
|
||||
method double ()
|
||||
return 2 * x
|
||||
end
|
||||
|
||||
# 'initially' block is called on instance construction
|
||||
initially (x)
|
||||
if /x # if x is null (not given), then set field to 0
|
||||
then self.x := 0
|
||||
else self.x := x
|
||||
end
|
||||
|
||||
procedure main ()
|
||||
x1 := Example () # new instance with default value of x
|
||||
x2 := Example (2) # new instance with given value of x
|
||||
write (x1.x)
|
||||
write (x2.x)
|
||||
write (x2.double ()) # call a method
|
||||
end
|
||||
22
Task/Classes/Pluto/classes.pluto
Normal file
22
Task/Classes/Pluto/classes.pluto
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class bear
|
||||
-- Constructs a Bear instance passing it a name
|
||||
-- which is stored in a private field to avoid external mutation.
|
||||
function __construct(private name) end
|
||||
|
||||
-- Property to get the name
|
||||
function name() return self.name end
|
||||
|
||||
-- Method to make a noise.
|
||||
function make_noise()
|
||||
print("Growl!")
|
||||
end
|
||||
end
|
||||
|
||||
-- Create a new bear instance and assign a reference to it
|
||||
-- to the variable b.
|
||||
local b = new bear("Bruno")
|
||||
|
||||
-- Print the bear's name.
|
||||
print($"The bear is called {b:name()}.")
|
||||
-- Make a noise.
|
||||
b:make_noise()
|
||||
28
Task/Classes/PowerShell/classes-1.ps1
Normal file
28
Task/Classes/PowerShell/classes-1.ps1
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
Add-Type -Language CSharp -TypeDefinition @'
|
||||
public class MyClass
|
||||
{
|
||||
public MyClass()
|
||||
{
|
||||
}
|
||||
public void SomeMethod()
|
||||
{
|
||||
}
|
||||
private int _variable;
|
||||
public int Variable
|
||||
{
|
||||
get { return _variable; }
|
||||
set { _variable = value; }
|
||||
}
|
||||
public static void Main()
|
||||
{
|
||||
// instantiate it
|
||||
MyClass instance = new MyClass();
|
||||
// invoke the method
|
||||
instance.SomeMethod();
|
||||
// set the variable
|
||||
instance.Variable = 99;
|
||||
// get the variable
|
||||
System.Console.WriteLine( "Variable=" + instance.Variable.ToString() );
|
||||
}
|
||||
}
|
||||
'@
|
||||
17
Task/Classes/PowerShell/classes-2.ps1
Normal file
17
Task/Classes/PowerShell/classes-2.ps1
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class MyClass
|
||||
{
|
||||
[type]$MyProperty1
|
||||
[type]$MyProperty2 = "Default value"
|
||||
|
||||
# Constructor
|
||||
MyClass( [type]$MyParameter1, [type]$MyParameter2 )
|
||||
{
|
||||
# Code
|
||||
}
|
||||
|
||||
# Method ( [returntype] defaults to [void] )
|
||||
[returntype] MyMethod( [type]$MyParameter3, [type]$MyParameter4 )
|
||||
{
|
||||
# Code
|
||||
}
|
||||
}
|
||||
33
Task/Classes/PowerShell/classes-3.ps1
Normal file
33
Task/Classes/PowerShell/classes-3.ps1
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
class Banana
|
||||
{
|
||||
# Properties
|
||||
[string]$Color
|
||||
[boolean]$Peeled
|
||||
|
||||
# Default constructor
|
||||
Banana()
|
||||
{
|
||||
$This.Color = "Green"
|
||||
}
|
||||
|
||||
# Constructor
|
||||
Banana( [boolean]$Peeled )
|
||||
{
|
||||
$This.Color = "Green"
|
||||
$This.Peeled = $Peeled
|
||||
}
|
||||
|
||||
# Method
|
||||
Ripen()
|
||||
{
|
||||
If ( $This.Color -eq "Green" ) { $This.Color = "Yellow" }
|
||||
Else { $This.Color = "Brown" }
|
||||
}
|
||||
|
||||
# Method
|
||||
[boolean] IsReadyToEat()
|
||||
{
|
||||
If ( $This.Color -eq "Yellow" -and $This.Peeled ) { return $True }
|
||||
Else { return $False }
|
||||
}
|
||||
}
|
||||
5
Task/Classes/PowerShell/classes-4.ps1
Normal file
5
Task/Classes/PowerShell/classes-4.ps1
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
$MyBanana = [banana]::New()
|
||||
$YourBanana = [banana]::New( $True )
|
||||
$YourBanana.Ripen()
|
||||
If ( -not $MyBanana.IsReadyToEat() -and $YourBanana.IsReadyToEat() )
|
||||
{ $MySecondBanana = $YourBanana }
|
||||
39
Task/Classes/Rebol/classes.rebol
Normal file
39
Task/Classes/Rebol/classes.rebol
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
Rebol [
|
||||
Title: "Classes"
|
||||
URL: http://rosettacode.org/wiki/Classes
|
||||
]
|
||||
|
||||
; Objects are derived from the base 'object!' type. Rebol uses a
|
||||
; prototyping object system, so any object can be treated as a class,
|
||||
; from which to derive others.
|
||||
|
||||
cowboy: make object! [
|
||||
name: "Tex" ; Instance variable.
|
||||
hi: does [ ; Method.
|
||||
print [self/name ": Howdy!"]]
|
||||
]
|
||||
|
||||
; I create two instances of the 'cowboy' class.
|
||||
|
||||
tex: make cowboy []
|
||||
roy: make cowboy [
|
||||
name: "Roy" ; Override 'name' property.
|
||||
]
|
||||
|
||||
print "Say 'hello', boys:" tex/hi roy/hi
|
||||
print ""
|
||||
|
||||
; Now I'll subclass 'cowboy'. Subclassing looks a lot like instantiation:
|
||||
|
||||
legend: make cowboy [
|
||||
deed: "..."
|
||||
boast: does [
|
||||
print [self/name ": I once" self/deed "!"]]
|
||||
]
|
||||
|
||||
; Instancing the legend:
|
||||
|
||||
pecos: make legend [name: "Pecos Bill" deed: "lassoed a twister"]
|
||||
|
||||
print "Howdy, Pecos!" pecos/hi
|
||||
print "Tell us about yourself?" pecos/boast
|
||||
30
Task/Classes/Red/classes.red
Normal file
30
Task/Classes/Red/classes.red
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
bike: object [
|
||||
frame-material: "aluminium"
|
||||
wheel-size: 29
|
||||
color: "black"
|
||||
set-color: func [value][color: value]
|
||||
]
|
||||
|
||||
e-bike: make bike [
|
||||
motor-type: "brushless"
|
||||
]
|
||||
print ["e-bike/frame-material : " e-bike/frame-material]
|
||||
print ["e-bike/motor-type : " e-bike/motor-type]
|
||||
|
||||
|
||||
mountain-bike: make bike [
|
||||
fork-stroke: 150
|
||||
]
|
||||
|
||||
green-mountain-bike: copy mountain-bike
|
||||
green-mountain-bike/set-color "green"
|
||||
|
||||
print ["green-mountain-bike/wheel-size : " green-mountain-bike/wheel-size]
|
||||
print ["green-mountain-bike/fork-stroke : " green-mountain-bike/fork-stroke]
|
||||
print ["green-mountain-bike/color : " green-mountain-bike/color]
|
||||
|
||||
default-mountain-bike: copy mountain-bike
|
||||
|
||||
print ["default-mountain-bike/wheel-size : " default-mountain-bike/wheel-size]
|
||||
print ["default-mountain-bike/fork-stroke : " default-mountain-bike/fork-stroke]
|
||||
print ["default-mountain-bike/color : " default-mountain-bike/color]
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
// 'pub'
|
||||
// all fields below 'pub mut:' would be public and mutable, while those above it, would not
|
||||
|
||||
pub struct Public {
|
||||
pub:
|
||||
data string
|
||||
data_1 string = "Hello" // other modules can not change
|
||||
pub mut:
|
||||
data_2 string // other modules can change
|
||||
data_3 string // other modules can change
|
||||
}
|
||||
|
||||
struct Private {
|
||||
|
|
@ -19,8 +21,8 @@ module sample
|
|||
|
||||
@[noinit]
|
||||
pub struct Information {
|
||||
pub:
|
||||
data string
|
||||
pub:
|
||||
data string = "Mike"
|
||||
}
|
||||
|
||||
// factory function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue