Removed redundant constant named origin.

This commit is contained in:
Christian Rinderknecht 2020-04-15 12:00:54 +02:00
parent fb7abe045f
commit a2c03ad848

View File

@ -138,12 +138,10 @@ updated record.
Let us consider defining a function that translates three-dimensional Let us consider defining a function that translates three-dimensional
points on a plane. points on a plane.
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
In PascaLIGO, the shape of that expression is In PascaLIGO, the shape of that expression is
`<record variable> with <record value>`. `<record variable> with <record value>`.
The record variable is the record to update and the The record variable is the record to update and the
record value is the update itself. record value is the update itself.
@ -239,17 +237,17 @@ For example if you have the following record structure:
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo ```pascaligo
type color is type color is
| Blue | Blue
| Green | Green
type preferences is record [ type preferences is record [
color : color; color : color;
other : int; other : int;
] ]
type account is record [ type account is record [
id : int; id : int;
preferences : preferences; preferences : preferences;
] ]
``` ```
@ -258,8 +256,8 @@ type account is record [
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo ```cameligo
type color = type color =
Blue Blue
| Green | Green
type preferences = { type preferences = {
@ -277,8 +275,8 @@ type account = {
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo ```reasonligo
type color = type color =
Blue Blue
| Green; | Green;
type preferences = { type preferences = {
@ -287,7 +285,7 @@ type preferences = {
} }
type account = { type account = {
id : int, id : int,
preferences : preferences preferences : preferences
} }
``` ```
@ -300,18 +298,18 @@ You can update the nested record with the following code:
```pascaligo ```pascaligo
function change_color_preference (const account : account; const color : color ) : account is function change_color_preference (const account : account; const color : color ) : account is
block { block {
account := account with record [preferences.color = color] account := account with record [preferences.color = color]
} with account } with account
``` ```
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo ```cameligo
let change_color_preference (account : account) (color : color) : account = let change_color_preference (account : account) (color : color) : account =
{ account with preferences.color = color } { account with preferences.color = color }
``` ```
@ -319,7 +317,7 @@ let change_color_preference (account : account) (color : color) : account =
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo ```reasonligo
let change_color_preference = (account : account, color : color): account => let change_color_preference = (account : account, color : color): account =>
{ ...account, preferences.color: color }; { ...account, preferences.color: color };
``` ```
@ -348,8 +346,6 @@ points on a plane.
type point is record [x : int; y : int; z : int] type point is record [x : int; y : int; z : int]
type vector is record [dx : int; dy : int] type vector is record [dx : int; dy : int]
const origin : point = record [x = 0; y = 0; z = 0]
function xy_translate (var p : point; const vec : vector) : point is function xy_translate (var p : point; const vec : vector) : point is
block { block {
patch p with record [x = p.x + vec.dx]; patch p with record [x = p.x + vec.dx];
@ -374,8 +370,6 @@ the value of `p` indeed changed. So, a shorter version would be
type point is record [x : int; y : int; z : int] type point is record [x : int; y : int; z : int]
type vector is record [dx : int; dy : int] type vector is record [dx : int; dy : int]
const origin : point = record [x = 0; y = 0; z = 0]
function xy_translate (var p : point; const vec : vector) : point is function xy_translate (var p : point; const vec : vector) : point is
block { block {
patch p with record [x = p.x + vec.dx; y = p.y + vec.dy] patch p with record [x = p.x + vec.dx; y = p.y + vec.dy]
@ -399,8 +393,6 @@ one we want to update* and use a functional update, like so:
type point is record [x : int; y : int; z : int] type point is record [x : int; y : int; z : int]
type vector is record [dx : int; dy : int] type vector is record [dx : int; dy : int]
const origin : point = record [x = 0; y = 0; z = 0]
function xy_translate (var p : point; const vec : vector) : point is function xy_translate (var p : point; const vec : vector) : point is
block { block {
const p : point = p with record [x = p.x + vec.dx; y = p.y + vec.dy] const p : point = p with record [x = p.x + vec.dx; y = p.y + vec.dy]
@ -1151,4 +1143,3 @@ let updated_map : register =
``` ```
</Syntax> </Syntax>