# Idiom #5 Create a 2D Point data structure

Declare a container type for two floating-point numbers x and y

`PointAsATuple = {X, Y}.`
```-module(points).
-export([new/2, x/1, y/1]).

-opaque point() :: #{x => float(), y => float()}.
-export_type([point/0]).

-spec new(float(), float()) -> point().
new(X, Y) -> #{x => X, y => Y}.

-spec x(point()) -> float().
x(#{x := X}) -> X.

-spec y(point()) -> float().
y(#{y := Y}) -> Y.```
`PointAsAMap = #{x => X, y => Y}.`
```type Point is
record
X : Float;
Y : Float;
end record;```
```typedef struct {
double x;
double y;
} Point;```
```type point = {
x: float;
y: float;
}```
`[x y]`
```struct Point{
double x;
double y;
};```
```struct Point{
double x;
double y;
};```
```struct Point
{
public double x;
public double y;
};```
```struct Point{
double x;
double y;
}

```
```class Point
{
float x;
float y;
}```
```class Point {
double x, y;
}```
```class Point {
double x, y;
Point(this.x, this.y);
}```
```{x, y}
defmodule Point do
defstruct x: 0.0, y: 0.0
end```
```p = [ x: 1.122, y: 7.45 ]
```
```type point
real :: x
real :: y
end type point```
```module x
type point
real :: x, y
end type point
end module x
```
```type Point struct {
x, y float64
}```
```data Point = Point
{ x :: Double
, y :: Double
} deriving (Eq, Ord, Show, Read)```
```data Point = Point
{ x :: Double
, y :: Double
}```
`var p = { x: 1.122, y: 7.45 };`
`const point = { x: 1, y: 2 };`
```class Point{
double x;
double y;
}```
`data class Point(val x: Float, val y: Float)`
```(defstruct point
(x 0.0d0 :type double-float)
(y 0.0d0 :type double-float))```
`point = { x = 123, y = 456 }`
```class Point
{
/** @var float */
public \$x = 0.0;

/** @var float */
public \$y = 0.0;
}```
```Type
TPoint = Record
x : Double;
y : Double;
End;```
`my \$point = [ 1.5, 6.3 ];`
`my \$point = { x => 1, y => 2 };`
`from dataclasses import dataclass`
```@dataclass
class Point:
x: float
y: float```
`Point = Struct.new(:x, :y)`
`struct Point { x: f64, y: f64, }`
`case class Point(x: Float, y: Float)`
```(define (make-point x y)
(cons x y))
(define (point-x p)
(car p))
(define (point-y p)
(cdr p))```
```Public Class Point
Public x As Single
Public y As Single
End Class```

#### Idiom created by

programming-idioms.org