Compound data type: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
m (→{{header|Wren}}: Changed to Wren S/H) |
|||
(9 intermediate revisions by 8 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 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
{
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}}==
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,269 ⟶ 1,310:
{A.last {R}}
-> 2
</syntaxhighlight>
=={{header|Lang}}==
<syntaxhighlight lang="lang">
&Point = {
$x
$y
}
</syntaxhighlight>
Line 2,286 ⟶ 2,335:
===Class instance===
<syntaxhighlight lang="raku" line>class Point { has Real ($.x
my Point $point .= new
===[http://design.raku.org/S32/Containers.html#Set Set]===
Line 2,710 ⟶ 2,759:
End Structure</syntaxhighlight>
=={{header|V (Vlang)}}==
Vlang also supports embedding structs into other structs and assigning methods to structs.
<syntaxhighlight lang="v (vlang)">struct Point {
x int
y int
Line 2,752 ⟶ 2,801:
=={{header|Wren}}==
<syntaxhighlight lang="
construct new(x, y) {
_x = x
|