Sign in Join
Wiki copytemporary

Becomes: what changed

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

OldNewLine
11:=
22
33The 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.
44
5-## Contents
6-
7- * 1 assignment
8- * 2 handling of special data types
9- * 3 syntax justification
10- * 4 index specification
11- * 5 see also
12-
135## assignment
146
157For 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.
168```
179program assignmentDemo(input, output, stderr);
1810
1911 const
2012 diameter = 6;
2113
2214 var
2315 n: integer;
2416 area: real;
2517 givenName: string;
2618
2719 begin
2820 n := 42;
2921 area := pi() * diameter;
3022 givenName := 'Smith';
3123 n := 1000 - n div 2;
3224 end.
3325```
3426
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.
27+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.
3628```
3729program assignmentRange(input, output, stderr);
3830
3931 type
4032 naturalNumber = 1..high(longword);
4133
4234 var
4335 n: naturalNumber;
4436
4537 begin
4638 {$rangechecks on}
4739 n := 1; // is OK
4840 n := -42 + n; // will cause RTE 201
4941 end.
5042```
5143
5244## handling of special data types
5345
5446Where 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.
5547
5648The compiler will generate appropriate code _copying_ data for following data types.
5749
5850 * [[String|`string`]]
5951 * [[Object|`object`]]
6052 * [[Record|`record`]]
6153
6254You don’t have to iterate over all components copying each element by hand as it is required in other programming languages.
6355
6456## syntax justification
6557
6658The 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.
6759
6860In comparison other languages than Pascal allow to write
6961```
7062n = m = x;
7163```
7264
7365The 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.
7466
7567In Pascal the code excerpt above is illegal. Non-productive statements are not allowed, i. e. _something_ has to be _done_.
7668
7769## index specification
7870
7971In 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.
8072
8173## see also
8274
8375 * [[Single assignment|single assignment]], a compiler optimization
8476
8577
8678
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-****
79+**navigation bar: topic: Pascal symbols**
80+
81+_single characters:_ [[Plus|`+` (plus)]] • [[Minus|`-` (minus)]] • [[*|`*` (asterisk)]] • [[Slash|`/` (slash)]] • [[Equal|`=` (equal)]] • [[Greater than|`>` (greater than)]] • [[Less than|`<` (less than)]] • [[period|`.` (period)]] • [[Colon|`:` (colon)]] • [[;|`;` (semi colon)]] • [[^|`^` (hat)]] • [[@|`@` (at)]] • [[Dollar sign|`$` (dollar sign)]] • [[&|`&` (ampersand)]] • [[Hash|`#` (hash)]] • [['|`'` (single quote)]]
82+
83+_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)]]
9884
9985---
10086*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