Difference between revisions of "Colon"

From Free Pascal wiki
(review)
Line 15: Line 15:
 
* in [[Case|<syntaxhighlight lang="pascal" enclose="none">case</syntaxhighlight>]] selectors it closes a match-list
 
* in [[Case|<syntaxhighlight lang="pascal" enclose="none">case</syntaxhighlight>]] selectors it closes a match-list
 
* in [[Label|label]] definitions the colon seperates the instruction from the label name
 
* in [[Label|label]] definitions the colon seperates the instruction from the label name
* also some routines, especially the [[Write|<syntaxhighlight lang="pascal" enclose="none">write</syntaxhighlight>]] and <syntaxhighlight lang="pascal" enclose="none">writeLn</syntaxhighlight> procedures accept further parameters via colon separated arguments
+
* also some routines, especially the [[Str|<syntaxhighlight lang="pascal" enclose="none">Str</syntaxhighlight>]], [[Write|<syntaxhighlight lang="pascal" enclose="none">write</syntaxhighlight>]] and <syntaxhighlight lang="pascal" enclose="none">writeLn</syntaxhighlight> procedures accept further parameters via colon separated arguments
 +
* Offset / segment separation under DOS <syntaxhighlight lang="pascal" enclose="none">Mem[$B800:$0000]</syntaxhighlight>
  
 
The following example shows the most prevalent usage scenarios:
 
The following example shows the most prevalent usage scenarios:

Revision as of 18:02, 22 April 2018

English (en) suomi (fi) français (fr) русский (ru) 中文(中国大陆)‎ (zh_CN)

:


The symbol :, pronounced “colon”, is used in Pascal in several ways:

  • in an identifier declaration it seperates the type
    • most notably in var sections
    • but also in const sections (in case of explicitely typed constants)
    • procedure and function parameters have a type, too
    • and return values of functions (including operator overloads)
    • as well as properties
    • in general, everywhere where a new identifier associated with some memory, is introduced (also custom structured type definitions)
  • in case selectors it closes a match-list
  • in label definitions the colon seperates the instruction from the label name
  • also some routines, especially the Str, write and writeLn procedures accept further parameters via colon separated arguments
  • Offset / segment separation under DOS Mem[$B800:$0000]

The following example shows the most prevalent usage scenarios:

 1 program colonDemo(input, output, stderr);
 2 
 3 procedure numberReport(const i: int64);
 4 begin
 5 	case i of
 6 		low(i)..-1:
 7 		begin
 8 			writeLn('Your number is negative. ☹');
 9 		end;
10 		1..high(i):
11 		begin
12 			// right aligns to a width of 24 characters
13 			writeLn(i:24);
14 		end;
15 		else
16 		begin
17 			writeLn('You''ve entered zero.');
18 		end;
19 	end;
20 end;
21 
22 var
23 	i: int64;
24 
25 begin
26 	writeLn('Enter a number:');
27 	readLn(i);
28 	numberReport(i);
29 end.

other remarks

  • Colon appears in the assignment operator :=.
  • In ASCII the character colon : has the value 58.



navigation bar: topic: Pascal symbols
single characters

+ (plus)  •  - (minus)  •  * (asterisk)  •  / (slash)
= (equal)  •  > (greater than)  •  < (less than)
. (period)  •  : (colon)  •  ; (semi colon)
^ (hat)  •  @ (at)
$ (dollar sign)  •  & (ampersand)  •  # (hash)
' (single quote)

character pairs

<> (not equal)  •  <= (less than or equal)  •  := (becomes)  •  >= (greater than or equal)

 •  >< (symmetric difference)  •  // (double slash)