Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,9 +0,0 @@
|
|||
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;
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
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;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
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;
|
||||
|
|
@ -1,53 +1,51 @@
|
|||
; defining a custom type
|
||||
define :person [ ; define a new custom type "Person"
|
||||
name ; with fields: name, surname, age
|
||||
surname
|
||||
age
|
||||
][
|
||||
; with custom post-construction initializer
|
||||
init: [
|
||||
this\name: capitalize this\name
|
||||
define :person [
|
||||
; define a new custom type "Person"
|
||||
; with fields: name, surname, age
|
||||
|
||||
init: method [name, surname, age][
|
||||
this\name: capitalize name
|
||||
this\surname: surname
|
||||
this\age: age
|
||||
]
|
||||
|
||||
; custom print function
|
||||
print: [
|
||||
string: method [][
|
||||
render "NAME: |this\name|, SURNAME: |this\surname|, AGE: |this\age|"
|
||||
]
|
||||
|
||||
; custom comparison operator
|
||||
compare: 'age
|
||||
]
|
||||
compare: sortable 'age
|
||||
|
||||
; create a method for our custom type
|
||||
sayHello: function [this][
|
||||
ensure -> is? :person this
|
||||
|
||||
print ["Hello" this\name]
|
||||
; create a method for our custom type
|
||||
sayHello: method [][
|
||||
print ["Hello" this\name]
|
||||
]
|
||||
]
|
||||
|
||||
; create new objects of our custom type
|
||||
a: to :person ["John" "Doe" 34] ; let's create 2 "Person"s
|
||||
b: to :person ["jane" "Doe" 33] ; and another one
|
||||
|
||||
; call pseudo-inner method
|
||||
sayHello a ; Hello John
|
||||
sayHello b ; Hello Jane
|
||||
do ::
|
||||
; call inner method
|
||||
a\sayHello ; Hello John
|
||||
b\sayHello ; Hello Jane
|
||||
|
||||
; access object fields
|
||||
print ["The first person's name is:" a\name] ; The first person's name is: John
|
||||
print ["The second person's name is:" b\name] ; The second person's name is: Jane
|
||||
; access object fields
|
||||
print ["The first person's name is:" a\name] ; The first person's name is: John
|
||||
print ["The second person's name is:" b\name] ; The second person's name is: Jane
|
||||
|
||||
; changing object fields
|
||||
a\name: "Bob"
|
||||
sayHello a ; Hello Bob
|
||||
; changing object fields
|
||||
a\name: "Bob"
|
||||
a\sayHello ; Hello Bob
|
||||
|
||||
; verifying object type
|
||||
print type a ; :person
|
||||
print is? :person a ; true
|
||||
; verifying object type
|
||||
print type a ; :person
|
||||
print is? :person a ; true
|
||||
|
||||
; printing objects
|
||||
print a ; NAME: John, SURNAME: Doe, AGE: 34
|
||||
; printing objects
|
||||
print a ; NAME: John, SURNAME: Doe, AGE: 34
|
||||
|
||||
; sorting user objects (using custom comparator)
|
||||
sort @[a b] ; Jane..., John...
|
||||
sort.descending @[a b] ; John..., Jane...
|
||||
; sorting user objects (using custom comparator)
|
||||
sort @[a b] ; Jane..., John...
|
||||
sort.descending @[a b] ; John..., Jane...
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
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.
|
||||
|
|
@ -2,11 +2,11 @@ import extensions;
|
|||
|
||||
class MyClass
|
||||
{
|
||||
int Variable : prop;
|
||||
int Variable : prop(_variable);
|
||||
|
||||
someMethod()
|
||||
{
|
||||
Variable := 1
|
||||
_variable := 1
|
||||
}
|
||||
|
||||
constructor()
|
||||
|
|
@ -14,7 +14,7 @@ class MyClass
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
// instantiate the class
|
||||
var instance := new MyClass();
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
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() );
|
||||
}
|
||||
}
|
||||
'@
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
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 }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
$MyBanana = [banana]::New()
|
||||
$YourBanana = [banana]::New( $True )
|
||||
$YourBanana.Ripen()
|
||||
If ( -not $MyBanana.IsReadyToEat() -and $YourBanana.IsReadyToEat() )
|
||||
{ $MySecondBanana = $YourBanana }
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue