Sign in Join
Wiki copytemporary

Becomes: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-=
2-
3-The character pair `:=`, that are a [[Colon|colon]] and an [[Equal|equal sign]] back to back, is pronounced as “becomes” and used by [[Pascal]] as the assignment operator.\
4-
5-## assignment
1+:=
62
7-For valid assignments `:=` is surrounded by a *single* [[Variable|variable]] [[Identifier|identifier]] on the left hand (possibly doing a [[Typecast|variable typecast]]), and an [[expression]] evaluating to the [[Data type|data type]] the variable is declared as on the right hand.
3+The character pair `:=`, that are a [[Colon|colon]] and an [[Equal|equal sign]] back to back, is pronounced as “becomes” and used by [[Pascal]] as the assignment operator.
84
9-``` pascal
10-program assignmentDemo(input, output, stderr);
5+## Contents
116
12-const
13- diameter = 6;
7+ * 1 assignment
8+ * 2 handling of special data types
9+ * 3 syntax justification
10+ * 4 index specification
11+ * 5 see also
1412
15-var
16- n: integer;
17- area: real;
18- givenName: string;
13+## assignment
1914
20-begin
21- n := 42;
22- area := pi() * diameter;
23- givenName := 'Smith';
24- n := 1000 - n div 2;
25-end.
15+For valid assignments `:=` is surrounded by a _single_ [[Variable|variable]] [[Identifier|identifier]] on the left hand (possibly doing a [[Typecast|variable typecast]]), and an [[expression]] evaluating to the [[Data type|data type]] the variable is declared as on the right hand.
2616```
27-
28-Assignments to variables of a [[subrange types|subrange type]] should be handled with care. The [[Compiler|compiler]] can only yield out-of-range errors for *[[Constant|constant]]* expressions, i. e. not depending on any [[runtime|run-time]] data. With [[sRangechecks|{$rangeChecks}]] enabled a [[runtime error|run-time error]] can be generated.
17+program assignmentDemo(input, output, stderr);
18+
19+ const
20+ diameter = 6;
21+
22+ var
23+ n: integer;
24+ area: real;
25+ givenName: string;
26+
27+ begin
28+ n := 42;
29+ area := pi() * diameter;
30+ givenName := 'Smith';
31+ n := 1000 - n div 2;
32+ end.
33+```
2934
30-``` pascal
35+Assignments to variables of a [[subrange types|subrange type]] should be handled with care. The [[Compiler|compiler]] can only yield out-of-range errors for _[[Constant|constant]]_ expressions, i. e. not depending on any [[runtime|run-time]] data. With [`{$rangeChecks}`](</index.php?title=sRangechecks&action=edit&redlink=1> "sRangechecks \(page does not exist\)") enabled a [[runtime error|run-time error]] can be generated.
36+```
3137program assignmentRange(input, output, stderr);
32-
33-type
34- naturalNumber = 1..high(longword);
35-
36-var
37- n: naturalNumber;
38-
39-begin
40- {$rangechecks on}
41- n := 1; // is OK
42- n := -42 + n; // will cause RTE 201
43-end.
38+
39+ type
40+ naturalNumber = 1..high(longword);
41+
42+ var
43+ n: naturalNumber;
44+
45+ begin
46+ {$rangechecks on}
47+ n := 1; // is OK
48+ n := -42 + n; // will cause RTE 201
49+ end.
4450```
4551
4652## handling of special data types
4753
48-Where simple data types like [[Integer|integers]] and [[Char|characters]] are realized as `mov` instructions or alike, data types that require initialization and finalization such as [[Ansistring|ansistrings]] or [[Class|classes]] need special care.
54+Where simple data types like [[Integer|`integer`s]] and [[Char|`char`acters]] are realized as `mov` instructions or alike, data types that require initialization and finalization such as [[Ansistring|`ansistring`s]] or [[Class|`class`es]] need special care.
4955
50-The compiler will generate appropriate code *copying* data for following data types.
56+The compiler will generate appropriate code _copying_ data for following data types.
5157
52-- [[String|string]]
53-- [[Object|object]]
54-- [[Record|record]]
58+ * [[String|`string`]]
59+ * [[Object|`object`]]
60+ * [[Record|`record`]]
5561
56-You don’t have to iterate over all components copying each element by hand as it is required in other programming languages.
62+You don’t have to iterate over all components copying each element by hand as it is required in other programming languages.
5763
5864## syntax justification
5965
60-The rationale of using two characters for assignment instead of just one, say the `=` sign, is to distinguish between assigning values and comparing for equality. It’s got its roots in the field of mathematics where a single equal sign is read as an expression, but has no imperative connotation.
61-
62-In comparison other languages than Pascal allow to write
66+The rationale of using two characters for assignment instead of just one, say the `=` sign, is to distinguish between assigning values and comparing for equality. It’s got its roots in the field of mathematics where a single equal sign is read as an expression, but has no imperative connotation.
6367
64-``` C
68+In comparison other languages than Pascal allow to write
69+```
6570n = m = x;
6671```
6772
68-The semantics of this line of code varies among every programming language. For instance, in [[Fortran]] and in Basic this line means “Compare the values `m` and `x`, and if they are equal to each other `n` becomes `true`, `false` otherwise.” In contrast to that the C programming language will assign `m` the value of `x`, and subsequently assign the `n` the value of `m`, so `n` and `m` both have the value `x`. This sort of code has been a common source of errors, compilers nowadays even emit warnings when encountering multiple assignment in a single line.
73+The semantics of this line of code varies among every programming language. For instance, in [[Fortran]] and in Basic this line means “Compare the values `m` and `x`, and if they are equal to each other `n` becomes `true`, `false` otherwise.” In contrast to that the C programming language will assign `m` the value of `x`, and subsequently assign the `n` the value of `m`, so `n` and `m` both have the value `x`. This sort of code has been a common source of errors, compilers nowadays even emit warnings when encountering multiple assignment in a single line.
6974
70-In Pascal the code excerpt above is illegal. Non-productive statements are not allowed, i. e. *something* has to be *done*.
75+In Pascal the code excerpt above is illegal. Non-productive statements are not allowed, i. e. _something_ has to be _done_.
7176
7277## index specification
7378
74-In declarations of enumerated data types, `:=` can be used to explicitly specify the ordinal value of a member. See [[Enum Type|enumeration types § “Indices”]] for details.
79+In declarations of enumerated data types, `:=` can be used to explicitly specify the ordinal value of a member. See [[Enum Type|enumeration types § “Indices”]] for details.
7580
7681## see also
7782
78-- [[Single assignment|single assignment]], a compiler optimization
83+ * [[Single assignment|single assignment]], a compiler optimization
7984
85+
86+
87+navigation bar: topic: Pascal symbols single characters | [[Plus|`+` (plus)]] • [[Minus|`-` (minus)]] • [[*|`*` (asterisk)]] • [[Slash|`/` (slash)]]
88+[[Equal|`=` (equal)]] • [[Greater than|`>` (greater than)]] • [[Less than|`<` (less than)]]
89+[[period|`.` (period)]] • [[Colon|`:` (colon)]] • [[;|`;` (semi colon)]]
90+[[^|`^` (hat)]] • [[@|`@` (at)]]
91+[[Dollar sign|`$` (dollar sign)]] • [[&|`&` (ampersand)]] • [`#` (hash)](</index.php?title=Hash&action=edit&redlink=1> "Hash \(page does not exist\)")
92+[['|`'` (single quote)]]
93+---|---
94+character pairs | [[Not equal|`<>` (not equal)]] • [[Less than or equal|`<=` (less than or equal)]] • `:=` (becomes) • [[Greater than or equal|`>=` (greater than or equal)]] • [[symmetric difference|`><` (symmetric difference)]] • [[Slash|`//` (double slash)]]
95+
96+
97+****
98+
8099---
81-*From the Free Pascal wiki, page "Becomes", as it stood on 2021-02-03 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
100+*From the Free Pascal wiki, page "Becomes", as the Internet Archive kept it on 2021-06-06, last changed on 2021-02-04. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history