Colon: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | 1 | The symbol `:`, pronounced “colon”, is used in [[Pascal]] in several ways: | |
| 7 | 2 | ||
| 8 | 3 | - in an [[Identifier|identifier]] declaration it separates the [[Type|type]] | |
| 9 | 4 | - most notably in [[Var|var]] sections | |
| 10 | 5 | - but also in [[Const|const]] sections (in case of *explicitely* typed constants) | |
| 11 | 6 | - [[Procedure|procedure]] and [[Function|function]] parameters have a type, too | |
| 12 | 7 | - and return values of functions (including operator overloads) | |
| 13 | 8 | - as well as [[Property|properties]] | |
| 14 | 9 | - in general, everywhere where a new identifier associated with some memory, is introduced (also custom structured type definitions) | |
| 15 | 10 | - in [[Case|case]] selectors it closes a match-list | |
| 16 | 11 | - in [[Label|label]] definitions the colon seperates the instruction from the label name | |
| 17 | 12 | - also some routines, especially the [[Str]], [[Write|write]] and `writeLn` procedures accept further parameters via colon separated arguments | |
| 18 | 13 | - Offset / segment separation under DOS `Mem[$B800:$0000]` | |
| 19 | 14 | ||
| 20 | 15 | The following example shows the most prevalent usage scenarios: | |
| 21 | 16 | ||
| 22 | 17 | ``` pascal | |
| 23 | 18 | program colonDemo(input, output, stderr); | |
| 24 | 19 | ||
| 25 | 20 | procedure numberReport(const i: int64); | |
| 26 | 21 | begin | |
| 27 | 22 | case i of | |
| 28 | 23 | low(i)..-1: | |
| 29 | 24 | begin | |
| 30 | 25 | writeLn('Your number is negative. ☹'); | |
| 31 | 26 | end; | |
| 32 | 27 | 1..high(i): | |
| 33 | 28 | begin | |
| 34 | 29 | // right aligns to a width of 24 characters | |
| 35 | 30 | writeLn(i:24); | |
| 36 | 31 | end; | |
| 37 | 32 | else | |
| 38 | 33 | begin | |
| 39 | 34 | writeLn('You''ve entered zero.'); | |
| 40 | 35 | end; | |
| 41 | 36 | end; | |
| 42 | 37 | end; | |
| 43 | 38 | ||
| 44 | 39 | var | |
| 45 | 40 | i: int64; | |
| 46 | 41 | ||
| 47 | 42 | begin | |
| 48 | 43 | writeLn('Enter a number:'); | |
| 49 | 44 | readLn(i); | |
| 50 | 45 | numberReport(i); | |
| 51 | 46 | end. | |
| 52 | 47 | ``` | |
| 53 | 48 | ||
| 54 | 49 | ## other remarks | |
| 55 | 50 | ||
| 56 | 51 | - Colon appears in the assignment operator [[Becomes|:=]]. | |
| 57 | 52 | - In [[ASCII]] the character colon `:` has the value `58`. | |
| 58 | 53 | ||
| 59 | 54 | --- | |
| 60 | 55 | *From the Free Pascal wiki, page "Colon", as it stood on 2022-08-06 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).* | |
| 61 | 56 | Category: Code |
