Compound data type: Difference between revisions

m
→‎{{header|Crystal}}: i missed that the task specifically calls for a Point data type
(→‎{{header|D}}: add crystal implementation with a link to the language reference)
m (→‎{{header|Crystal}}: i missed that the task specifically calls for a Point data type)
Line 520:
Crystal's structs work very similarly to objects, but are allocated on the stack instead of the heap, and passed by value instead of by reference. More potential caveats are noted in the [https://crystal-lang.org/reference/syntax_and_semantics/structs.html language reference].
 
<lang ruby>struct TwoTuplePoint(T)
getter fstx : T
getter sndy : T
def initialize(@fstx, @sndy)
end
end
 
puts TwoTuplePoint(Int32|String).new 4213, "foo"12 #=> TwoTuplePoint(Int32 | String)(@fstx=4213, @sndy="foo"12)</lang>
 
=={{header|D}}==
Anonymous user