Jump to content

Compound data type: Difference between revisions

Added Elixir
No edit summary
(Added Elixir)
Line 6:
 
{{Template:See also lists}}
 
=={{header|ACL2}}==
<lang Lisp>(defstructure point
Line 69 ⟶ 70:
end record;</lang>
In this case every person will have the attributes of gender, name, age, and weight. A person with a male gender will also have a beard length.
 
=={{header|ALGOL 68}}==
===Tagged Type===
Line 299 ⟶ 301:
console.log p1.distance_from p2 # 13
</lang>
 
 
=={{header|Common Lisp}}==
Line 415 ⟶ 416:
//Add new constructor to an existing type
data Several = Four</lang>
 
=={{header|Elixir}}==
<lang elixir>iex(1)> defmodule Point do
...(1)> defstruct x: 0, y: 0
...(1)> end
{:module, Point, <<70, 79, 82, ...>>, %Point{x: 0, y: 0}}
iex(2)> origin = %Point{}
%Point{x: 0, y: 0}
iex(3)> pa = %Point{x: 10, y: 20}
%Point{x: 10, y: 20}
iex(4)> pa.x
10
iex(5)> %Point{pa | y: 30}
%Point{x: 10, y: 30}
iex(6)> %Point{x: px, y: py} = pa # pattern matching
%Point{x: 10, y: 20}
iex(7)> px
10
iex(8)> py
20</lang>
 
=={{header|Erlang}}==
Line 429 ⟶ 450:
io:fwrite("X: ~f, Y: ~f~n",[P2#point.x,P2#point.y]).
</lang>
 
 
=={{header|Euphoria}}==
Line 540 ⟶ 560:
Seq.iter (fun p -> printfn "%d,%d" p.x p.y) points</lang>
 
=={{header|Go}}==
<lang go>package main
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.