# Idiom #5 Create a 2D Point data structure

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

class Point{
double x;
double y;
}
type Point is
record
X : Float;
Y : Float;
end record;
typedef struct {
double x;
double y;
} Point;
[x y]
struct Point {
double x;
double y;
};
typedef struct {
double x;
double y;
} Point;
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);
}
p = [ x: 1.122, y: 7.45 ]
-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.
PointAsATuple = {X, Y}.
PointAsAMap = #{x => X, y => Y}.
type point
real(kind=8) :: x
real(kind=8) :: y
end type point
type Point struct {
x, y float64
}
data Point = Point
{ x :: Double
, y :: Double
data Point = Point
{ x :: Double
, y :: Double
}
var p = { x: 1.122, y: 7.45 };
point = { x = 123, y = 456 }
<?php

class Point{
public \$x = 0.0;
public \$y = 0.0;
}
Type
TPoint = Record
x : Double;
y : Double;
End;
my \$point = [ 1.5, 6.3 ];
my \$point = { x=>1.5, y=>6.3 };
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
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))

#### Idiom created by

programming-idioms.org