September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
10
Task/Compound-data-type/ALGOL-W/compound-data-type.alg
Normal file
10
Task/Compound-data-type/ALGOL-W/compound-data-type.alg
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
begin
|
||||
% create the compound data type %
|
||||
record Point( real x, y );
|
||||
% declare a Point variable %
|
||||
reference(Point) p;
|
||||
% assign a value to p %
|
||||
p := Point( 1, 0.5 );
|
||||
% access the fields of p - note Algol W uses x(p) where many languages would use p.x %
|
||||
write( x(p), y(p) )
|
||||
end.
|
||||
27
Task/Compound-data-type/Elm/compound-data-type.elm
Normal file
27
Task/Compound-data-type/Elm/compound-data-type.elm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
--Compound Data type can hold multiple independent values
|
||||
--In Elm data can be compounded using List, Tuple, Record
|
||||
--In a List
|
||||
point = [2,5]
|
||||
--This creates a list having x and y which are independent and can be accessed by List functions
|
||||
--Note that x and y must be of same data type
|
||||
|
||||
--Tuple is another useful data type that stores different independent values
|
||||
point = (3,4)
|
||||
--Here we can have multiple data types
|
||||
point1 = ("x","y")
|
||||
point2 = (3,4.5)
|
||||
--The order of addressing matters
|
||||
--Using a Record is the best option
|
||||
point = {x=3,y=4}
|
||||
--To access
|
||||
point.x
|
||||
point.y
|
||||
--Or Use it as a function
|
||||
.x point
|
||||
.y point
|
||||
--Also to alter the value
|
||||
{point | x=7}
|
||||
{point | y=2}
|
||||
{point | x=3,y=4}
|
||||
--Each time a new record is generated
|
||||
--END
|
||||
9
Task/Compound-data-type/Kotlin/compound-data-type.kotlin
Normal file
9
Task/Compound-data-type/Kotlin/compound-data-type.kotlin
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
data class Point(var x: Int, var y: Int)
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val p = Point(1, 2)
|
||||
println(p)
|
||||
p.x = 3
|
||||
p.y = 4
|
||||
println(p)
|
||||
}
|
||||
20
Task/Compound-data-type/Oberon-2/compound-data-type.oberon-2
Normal file
20
Task/Compound-data-type/Oberon-2/compound-data-type.oberon-2
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
MODULE Point;
|
||||
TYPE
|
||||
Object* = POINTER TO ObjectDesc;
|
||||
ObjectDesc* = RECORD
|
||||
x-,y-: INTEGER;
|
||||
END;
|
||||
|
||||
PROCEDURE (p: Object) Init(x,y: INTEGER);
|
||||
BEGIN
|
||||
p.x := x; p.y := y
|
||||
END Init;
|
||||
|
||||
PROCEDURE New*(x,y: INTEGER): Object;
|
||||
VAR
|
||||
p: Object;
|
||||
BEGIN
|
||||
NEW(p);p.Init(x,y);RETURN p;
|
||||
END New;
|
||||
|
||||
END Point.
|
||||
11
Task/Compound-data-type/OoRexx/compound-data-type.rexx
Normal file
11
Task/Compound-data-type/OoRexx/compound-data-type.rexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
p = .point~new(3,4)
|
||||
say "x =" p~x
|
||||
say "y =" p~y
|
||||
|
||||
::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
|
||||
|
|
@ -1 +1,3 @@
|
|||
my @point = 3, 8;
|
||||
|
||||
my Int @point = 3, 8; # or constrain to integer elements
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
my %point = x => 3, y => 8;
|
||||
|
||||
my Int %point = x => 3, y => 8; # or constrain the hash to have integer values
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
Structure MyPoint
|
||||
X.i
|
||||
Y.i
|
||||
EndStructure
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
Structure MyFileDate
|
||||
name.s
|
||||
StructureUnion
|
||||
Date_as_txt.s
|
||||
Date_in_Ticks.l
|
||||
EndStructureUnion
|
||||
EndStructure
|
||||
16
Task/Compound-data-type/Stata/compound-data-type.stata
Normal file
16
Task/Compound-data-type/Stata/compound-data-type.stata
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
mata
|
||||
struct Point {
|
||||
real scalar x, y
|
||||
}
|
||||
|
||||
// dumb example
|
||||
function test() {
|
||||
struct Point scalar a
|
||||
a.x = 10
|
||||
a.y = 20
|
||||
printf("%f\n",a.x+a.y)
|
||||
}
|
||||
|
||||
test()
|
||||
30
|
||||
end
|
||||
7
Task/Compound-data-type/Zkl/compound-data-type-1.zkl
Normal file
7
Task/Compound-data-type/Zkl/compound-data-type-1.zkl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Point{ var x,y;
|
||||
fcn init(x,y){self.x=x.toFloat(); self.y=y.toFloat(); }
|
||||
fcn toString{ "P(%f,%f)".fmt(x,y) }
|
||||
fcn __opADD(P){} //+: add Point, constant or whatever
|
||||
//... __opEQ == etc
|
||||
}
|
||||
Point(1,2).println() //-->P(1.000000,2.000000)
|
||||
1
Task/Compound-data-type/Zkl/compound-data-type-2.zkl
Normal file
1
Task/Compound-data-type/Zkl/compound-data-type-2.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
point:=T(1,2); points:=T( T(1,2), L(3,4) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue