Compound data type: Difference between revisions

PascalABC.NET
(Add lang example)
(PascalABC.NET)
 
(7 intermediate revisions by 6 users not shown)
Line 575:
 
=={{header|COBOL}}==
A compound data item description is possible in COBOL as a subdivided record:
<syntaxhighlight lang="cobol">
<syntaxhighlight lang="cobol"> DATA DIVISION.
01 Point.
05 x WORKING-STORAGE pic 9(3)SECTION.
05 y 01 pic 9(3)Point.
05 x USAGE IS BINARY-SHORT.
</syntaxhighlight>
05 y USAGE IS BINARY-SHORT.</syntaxhighlight>
Here the record <code>Point</code> has the subdivisions <code>x</code> and <code>y</code>, both of which are signed 16-bit binary integers.
 
=={{header|CoffeeScript}}==
Line 745 ⟶ 747:
 
=={{header|Elena}}==
ELENA 6.x:
<syntaxhighlight lang="elena">struct Point
{
prop int X : prop;
prop int Y : prop;
constructor new(int x, int y)
Line 951 ⟶ 954:
3 4
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
CGRect r = {0, 0, 250, 100}
printf @"x = %.f : y = %.f : width = %.f : height = %.f", r.origin.x, r.origin.y, r.size.width, r.size.height
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
x = 0 : y = 0 : width = 250 : height = 100
 
</pre>
 
 
=={{header|Go}}==
Line 1,129 ⟶ 1,146:
Y__P
20</syntaxhighlight>
 
=={{header|Jakt}}==
<syntaxhighlight lang="coboljakt">
01struct Point. {
x: i64
y: i64
}
 
fn main() {
println("{}", Point(x: 3, y: 4))
}
</syntaxhighlight>
 
=={{header|Java}}==
Starting with Java 14 you can use a record
<syntaxhighlight lang="java">
record Point(int x, int y) { }
</syntaxhighlight>
Usage
<syntaxhighlight lang="java">
Point point = new Point(1, 2);
int x = point.x;
int y = point.y;
</syntaxhighlight>
<br />
Alternately
We use a class:
<syntaxhighlight lang="java">public class Point
Line 1,757 ⟶ 1,798:
x, y: integer;
end;</syntaxhighlight>
 
=={{header|PascalABC.NET}}==
Classes in PascalABC.NET are reference types and records are value types.
<syntaxhighlight lang="pascal">
type
Point = class
x,y: integer;
constructor(x,y: integer) := (Self.x,Self.y) := (x,y);
end;
PointRec = record
x,y: integer;
constructor(x,y: integer) := (Self.x,Self.y) := (x,y);
end;
 
begin
var p := new Point(2,3);
Println(p.x,p.y);
var pr := new PointRec(4,5);
Println(pr.x,pr.y);
end.
</syntaxhighlight>
 
=={{header|Perl}}==
Line 2,760 ⟶ 2,822:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">class Point {
construct new(x, y) {
_x = x
217

edits