Compound data type: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added Pike implementation) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 699:
--END
</lang>
=={{header|Erlang}}==
<lang erlang>
Line 1,004 ⟶ 1,005:
print, point
;=> { 6 7}</lang>
=={{header|J}}==
Line 1,341:
Alternatively, coordinates can be also stored as vectors
<lang MATLAB> point = [3,4];</lang>
=={{header|Maxima}}==
Line 1,363 ⟶ 1,362:
Point.x = 0
Point.y = 0</lang>
=={{header|Modula-2}}==
Line 1,620 ⟶ 1,618:
my $point = Point->new(x => 3, y => 8);</lang>
=={{header|Perl 6}}==▼
{{works with|Rakudo|#24 "Seoul"}}▼
===Array===▼
<lang perl6>my @point = 3, 8;▼
my Int @point = 3, 8; # or constrain to integer elements</lang>▼
===Hash===▼
<lang perl6>my %point = x => 3, y => 8;▼
my Int %point = x => 3, y => 8; # or constrain the hash to have integer values</lang>▼
===Class instance===▼
<lang perl6>class Point { has $.x is rw; has $.y is rw; }▼
my Point $point .= new(x => 3, y => 8);</lang>▼
===[http://design.perl6.org/S32/Containers.html#Set Set]===▼
<lang perl6>my $s1 = set <a b c d>; # order is not preserved▼
my $s2 = set <c d e f>;▼
say $s1 (&) $s2; # OUTPUT«set(c, e)»▼
say $s1 ∩ $s2; # we also do Unicode</lang>▼
=={{header|Phix}}==
Line 1,906 ⟶ 1,881:
(init-field x y)))
</lang>
(formerly Perl 6)
▲{{works with|Rakudo|#24 "Seoul"}}
▲===Array===
▲<lang perl6>my @point = 3, 8;
▲my Int @point = 3, 8; # or constrain to integer elements</lang>
▲===Hash===
▲<lang perl6>my %point = x => 3, y => 8;
▲my Int %point = x => 3, y => 8; # or constrain the hash to have integer values</lang>
▲===Class instance===
▲<lang perl6>class Point { has $.x is rw; has $.y is rw; }
▲my Point $point .= new(x => 3, y => 8);</lang>
▲===[http://design.perl6.org/S32/Containers.html#Set Set]===
▲<lang perl6>my $s1 = set <a b c d>; # order is not preserved
▲my $s2 = set <c d e f>;
▲say $s1 (&) $s2; # OUTPUT«set(c, e)»
▲say $s1 ∩ $s2; # we also do Unicode</lang>
=={{header|REXX}}==
Line 2,106 ⟶ 2,105:
30
end</lang>
=={{header|Swift}}==
<lang Swift>// Structure
Line 2,311:
<!-- context is a circle node. Children are accessed using a path-like notation (hence the name "XPath"). --></lang>
<fo:block>Circle center = <xsl:value-of select="point/x"/>, <xsl:value-of select="point/y"/></fo:block>
=={{header|zkl}}==▼
The OO solution:▼
<lang zkl>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)</lang>▼
which can be pretty heavy weight. [read only] lists can work just as well:▼
<lang zkl>point:=T(1,2); points:=T( T(1,2), L(3,4) )</lang>▼
{{omit from|bc}}▼
{{omit from|dc}}▼
=={{header|zonnon}}==
Line 2,338 ⟶ 2,353:
end Point;
</lang>
▲=={{header|zkl}}==
▲The OO solution:
▲<lang zkl>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)</lang>
▲which can be pretty heavy weight. [read only] lists can work just as well:
▲<lang zkl>point:=T(1,2); points:=T( T(1,2), L(3,4) )</lang>
▲{{omit from|bc}}
▲{{omit from|dc}}
|