Compound data type: Difference between revisions
Content added Content deleted
(→{{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: | 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]. |
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 |
<lang ruby>struct Point(T) |
||
getter |
getter x : T |
||
getter |
getter y : T |
||
def initialize(@ |
def initialize(@x, @y) |
||
end |
end |
||
end |
end |
||
puts |
puts Point(Int32).new 13, 12 #=> Point(Int32)(@x=13, @y=12)</lang> |
||
=={{header|D}}== |
=={{header|D}}== |